use strict;

Raf rafiq at
Mon Nov 10 04:19:31 CST 2003

andrew at work said:
> Rick, thanks for taking the time to reply and for your suggestions. I
> think they have pointed me in the right direction. I cant quite get my
> head around oop so I will be leaving that well alone for the time
> being, I'me sure one of the other ways will work fine for me.

Hi Andrew,

Just a quick note.  I used to work in an environment where lots of
'library' scripts were 'do'ed' and required.  My experience is that it's
a nice way to start out, however it really makes your code a bugger to
maintain, especially when 'library' 'do'es' 'library' 'do'es' library
and every variable is a global.

You should seriously adhere to Rick's suggestion of sticking your code
into a module and keeping some kind of package scoping around these
variables.  You'll want to checkout 'perldoc perlmod' which will start
you off.  Once you've got your head around this, which just tidies up
what you're doing now, you can then check out perldoc perlobj which will
make it easier to get your head around the oop stuff.

If others have to use your code in the future, they (and you) will be
glad that you made the switch over.



> ----- Original Message -----
> From: "Rick Measham" <rickm at>
> To: "andrew at work" <agray at>; <melbourne-pm at>
> Sent: Monday, November 10, 2003 10:11 AM
> Subject: Re: use strict;
> 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