We don't bite newbies here... much | |
PerlMonks |
DBI::mySQL - philosophical question?by jfrm (Monk) |
on Jan 29, 2004 at 00:21 UTC ( [id://324841]=perlquestion: print w/replies, xml ) | Need Help?? |
jfrm has asked for the wisdom of the Perl Monks concerning the following question:
A long time ago, brothers, I wrote a script and I didn't know what I was doing. It's grown big. I don't know much more now but I do know I should convert it to 'use strict' so I am. And a right PITA it has been (apologies for swearing in a temple). I'm almost there but one question remains. The script uses:
And here there and everywhere, there are statements like: I've converted these to have 'my' in front of each instance - I figured this was better practice than a single my ($statement,$sth,$rv,$rc) at the top of each perl file to cover all the subfunctions (I'm sure you'll tell me if I'm wrong). Anyway, previously, I connected to the database at the top: and then disconnected at the very end. And multiple database calls happened using this single connection. Now that I'm converting to 'use strict', each subfunction is naturally enough forcing me to declare the $dbh within it. So I presume my options are: 1. declare $dbh as a global variable, use 'our' within the subfunctions and carry on with a single connection. 2. connect and disconnect to the database for each separate database query. So my 'elegance' genie is telling me that I shouldn't use 'our' unless necessary so should go for 2. But my 'performance' genie is telling me that it's going to make everything take longer if I connect and disconnect over and over so I should opt for 1. Please oh fellow bowl carriers, your collective wisdom would be appreciated especially if you know of a magical option 3 which is the correct path for the righteous...
Back to
Seekers of Perl Wisdom
|
|