> > use strict;
> >
> > use vars qw( $a $b $c     # this is how you declare variables
> >            $myvar   );  # for use with "use strict"
> 
> I've always seen it done this way:
> 
> #[code]
> my ($a, $b, $c, $myvar);
> #[/code]
> 
> ...so that the variables are part of the current package.
> I kind of like the way you've done it, though.
> Why would you choose one of these over the other?

Both approaches will work equally well for most general applications.  You
start to see differences when you get into more specialized applications.
For example, if you're writing a Perl module, and you want to export
variables using Exporter.pm, you can't use "my".  "My" variables don't exist
outside the file in which they're defined, so obviously you can't refer to
them from any file that's going to be using your module.

The other example that comes to mind is if you ever get write CGI scripts
that run under mod_perl's CGI engine (dang, brain cramp, what's that
mod_perl thing called again?).  Anyway, there is a really esoteric
interaction that happens with "my" variables that causes them to hold on to
their initial value unexpectedly.  You see it sometimes in scripts that have
a user log in--the second person to log in (and everybody thereafter) gets
logged in as the first person who logged in, because a "my" variable held on
to its first value.  Look up "closure" in the Perl reference if you want
more info.

Anybody else want to chime in on this?

Mark Nutter
Manager, Internet Applications Development
Marconi
[EMAIL PROTECTED]
It's not necessarily an advantage to have better brakes than the guy behind
you.

Reply via email to