Problems? Is your data what you think it is? | |
PerlMonks |
A Better way? (Lots of routines with similar structure)by Ryszard (Priest) |
on Jun 08, 2003 at 19:58 UTC ( [id://264142]=perlquestion: print w/replies, xml ) | Need Help?? |
Ryszard has asked for the wisdom of the Perl Monks concerning the following question:
I'm writing a module whereby i have to update a normalised database. Before I add an entry, i need to check to see if its there before, and if it is, then add it, if not return the primary key et al.
In this case i'm updating a movie database. There are a few tables in it, for example a table for "actors", "plot", "director", "genre" etc etc. Tieing it all together is the main table that has a foreign key relationship with all the other tables. The way i'm doing it right now is i'm having one routine for each operation that has to be performed, ie one rouine to check to see the "actor" exists (and return its primary key if it does), then another routine to insert it if it doesnt. Now this can add up to a whole bunch of routines that are very similar, but essentially the same.
The _execute method is a hookup to an abstraction to the dbi. So, it occurred to me there would be better method of doing this, its just that, well, i cant think of it right now... Has anyone had any experience doing this? The core of the module is below to put it in better context.
update (broquaint): added <readmore> tag
Back to
Seekers of Perl Wisdom
|
|