in reply to Re^2: Scope, package, and 'my' variables
in thread Scope, package, and 'my' variables
{ my $var = 'first var'; # sets $var for this block # defines a sub IN this block, so gets this $var sub do_a { print "In 'aaa' var is set to '$var'\n"; } }
Because subroutine names are available globally, do_a can be called from anywhere, but gets the $var defined in its lexical block.
Similarly, do_b is defined in a block where $var is set to nothing, and do_c is in a block with no $var at all.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Scope, package, and 'my' variables
by ff (Hermit) on Jan 04, 2005 at 20:14 UTC | |
by chromatic (Archbishop) on Jan 05, 2005 at 04:52 UTC | |
by Errto (Vicar) on Jan 05, 2005 at 04:57 UTC |