in reply to Scope::Upper localize?
The following two things are roughly equivalent...
Using Scope::Upper...
use 5.010; use Scope::Upper qw(localize UP); our $foo = 42; sub foo { localize '$foo', 1, UP; } sub bar { say "start bar: ", $foo; foo(); say "end bar: ", $foo; } say "before bar: ", $foo; bar(); say "after bar: ", $foo;
Without Scope::Upper...
use 5.010; our $foo = 42; sub bar { say "start bar: ", $foo; local $foo = 1; say "end bar: ", $foo; } say "before bar: ", $foo; bar(); say "after bar: ", $foo;
So, essentially, what it does is allows you to change the value of a variable in your caller's scope, with the change reverting once the caller scope is finished.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Scope::Upper localize?
by Anonymous Monk on Sep 11, 2012 at 04:53 UTC |