use strict;
Rick Measham
rickm at printaform.com.au
Sun Nov 9 18:11:38 CST 2003
At 09:27 +1000 2003-11-10, andrew at work wrote:
>Is there a way to define global variables and
>keep using strict? Have I missed something else ?
Global vars are a Very Bad Thing. Especially if
you want to reference them from libraries. It's
not really a library if it requires a global
variable. If your library performs common
routines with database handles, then make the dbh
the first parameter to the function:
myLibrary::doSomething( $dbh, ... )
However, if you must use 'Global Variables', then in your main file:
use vars qw/$globalvar/;
$globalvar = 'some value';
And in your library, you can just use it:
print $globalvar
Or, if your libarry contains a package, use it as:
print $main::globalvar
Once again though, global variables are a bad thing
( Maybe have a look at going OO, then your )
.oO( object can contain your 'globals', including )
( database handles, cache objects & parameters )
Cheers!
Rick
More information about the Melbourne-pm
mailing list