in reply to local & global function
Maybe what you are after is somewhat like this:
use strict; { # just a block my $test; # the lexical one sub foo { print "In foo: \$test=$test\n"; $test = "Hello world"; print "In foo: \$test=$test\n"; } sub bar { print "In bar \$test=$test\n"; } } my $test; # the global one print "Global \$test=$test\n"; foo(); print "Global \$test=$test\n"; bar(); print "Global \$test=$test\n";
The two functions are defined in a block and therefore share the lexical (please do not use the term local in Perl) variables declared within that block ABOVE the functions.
Jenda
Enoch was right!
Enjoy the last years of Rome.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: local & global function (closures)
by LanX (Saint) on Oct 17, 2018 at 12:30 UTC |