Purdy has asked for the wisdom of the Perl Monks concerning the following question:
$database = "dbname"; require '/home/sites/jdb.cgi'; # now I can do whatever with $dbh
So when I slap in the '-w' (err, really I start with it - no honestly! :)), I get the following errors:
Name "main::dbh" used only once: possible typo at ./sqltest.pl line 8.
Name "main::database" used only once: possible typo at ./sqltest.pl line 5.
And if I 'use strict', I get:
Global symbol "$database" requires explicit package name at ./sqltest.pl line 5.
Global symbol "$dbh" requires explicit package name at ./sqltest.pl line 8.
Execution of ./sqltest.pl aborted due to compilation errors.
I put in a 'main::' in front of the variable names and that does fix it (not the warnings), but is that the solution? Putting 'main::' in front of everything?
I've heard of this 'our' declaration, but I don't have the latest version of Perl to have that (but if that's the answer, I'd still like to know).
If you check out the linked node, you'll see why I have/want this centralized script and the reason I designed it that way. But I don't like not being able to use the '-w' and 'use strict' ... am I doomed to have it only one way or another? Or is there a better way?
My next move is to read through the perldoc on the strict pragma. I guess I don't really understand that. But I'd still like to know if there's a better way to design such a system. Thanks in advance for the enlightenment! I look forward to learning an elegant solution. :)
Jason
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Good programming practice
by Fastolfe (Vicar) on Nov 03, 2001 at 21:06 UTC | |
by blakem (Monsignor) on Nov 04, 2001 at 12:58 UTC | |
by tretin (Friar) on Nov 04, 2001 at 10:39 UTC | |
by Aristotle (Chancellor) on Nov 05, 2001 at 02:09 UTC | |
Re: Good programming practice
by wog (Curate) on Nov 03, 2001 at 20:53 UTC | |
by Purdy (Hermit) on Nov 03, 2001 at 21:01 UTC | |
by jeffa (Bishop) on Nov 03, 2001 at 21:08 UTC | |
by Ven'Tatsu (Deacon) on Nov 04, 2001 at 02:05 UTC | |
Re: Good programming practice
by dragonchild (Archbishop) on Nov 05, 2001 at 21:11 UTC |