Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I'm having a bit of trouble with using some local scope variables. I have a function where I want to define a variable, then use that variable in a sub function. That sounds like the text book definition for when to use a local scope variable. Below is the test script that I'm using.
I'm using the 'use strict' declaration as all the books I've read (O'Reilly's) say that's a Good Thing to do.
Can someone offer some insight as to why when I declare $a it's ok, but declaring $aa gives me an error?
I'm using Active State's Perl v5.8.3 build 809 for Windows.
Thanks for any help
- Josh
use strict; test1(); sub test1 { local $a = 1; local $aa = 2; test2(); } sub test2 { print "a = $a\n"; print "aa = $aa\n"; } # Global symbol "$aa" requires explicit package name at C:\projects\Tr +acing\test.pl line 8. # Global symbol "$aa" requires explicit package name at C:\projects\Tr +acing\test.pl line 15. # Execution of C:\projects\Tracing\test.pl aborted due to compilation +errors.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Local Scope Variables
by bart (Canon) on Feb 13, 2004 at 01:47 UTC | |
|
Re: Local Scope Variables
by borisz (Canon) on Feb 12, 2004 at 23:42 UTC | |
|
Re: Local Scope Variables
by revdiablo (Prior) on Feb 13, 2004 at 08:32 UTC | |
by Anonymous Monk on Feb 14, 2004 at 23:43 UTC | |
by revdiablo (Prior) on Feb 15, 2004 at 00:29 UTC | |
|
Re: Local Scope Variables
by davido (Cardinal) on Feb 13, 2004 at 02:26 UTC | |
|
Re: Local Scope Variables
by PodMaster (Abbot) on Feb 12, 2004 at 23:38 UTC | |
|
Re: Local Scope Variables
by hhdave (Beadle) on Feb 12, 2004 at 23:51 UTC | |
by arden (Curate) on Feb 13, 2004 at 01:26 UTC | |
|
Re: Local Scope Variables
by mce (Curate) on Feb 13, 2004 at 08:10 UTC |