Here's a fuller answer. You should use "use strict" because it alerts you to
all sorts of questionable programming practices that may cause
hard-to-locate bugs. "use strict" is actually a shorthand for three things:
"use strict 'vars'", "use strict 'subs'", and "use strict 'refs'". It is the
use of "use strict 'vars'" that we are interested in here.

When "use strict 'vars'" is in effect and you are using a global variable
(such as $emailLog), Perl will issue a warning alerting you to that
fact--for example:

  Global symbol "$emailLog" requires explicit package name at t.pl line 5.

Since this is something that you *intend* to do, you can prevent the warning
by adding the following at the beginning of your script:

  use vars qw($emailLog);

This also has the effect of documenting your intent to use a global variable
to anyone who reads the code.

If you have multiple variables you want to declare, separate them by spaces:

  use vars qw($myScalar @myArray %myHash)


--greggw

> -----Original Message-----
> From: Maxim Berlin [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, June 26, 2001 9:14 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Variable scope
> 
> 
> Hello David,
> 
> Tuesday, June 26, 2001, David Gilden <[EMAIL PROTECTED]> wrote:
> 
> DG> Quick question,
> 
> DG> I could not get the following sub to work until 
> DG> I had to move  $emailLog inside the sub to get this 
> DG> to work on the server. 
> 
> DG> What did I miss or not understand?
> i suggest you always to place
> 
> use strict;
> 
> at the top of your program. then, you see errors:
> C:\TEMP>perl -c t.pl
> Global symbol "$emailLog" requires explicit package name at 
> t.pl line 5.
> Global symbol "$errorMssg" requires explicit package name at 
> t.pl line 41.
> 
> read more about my() and local() in perldoc perlfunc.
> 
> 
> Best wishes,
>  Maxim                            mailto:[EMAIL PROTECTED]
> 
> 
> 

Reply via email to