Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re^2: What's wrong with this local() ? (*)

by tye (Sage)
on Jan 30, 2008 at 08:14 UTC ( #665082=note: print w/replies, xml ) Need Help??

in reply to Re: What's wrong with this local() ?
in thread What's wrong with this local() ?

Actually, it is closer to:

# Save a reference to the original variable: *nothingToSeeHere::var= \$var; # Replace the variable with a new variable instance and assign # that new instance the given value (or undef if none mentioned): *var= \undef; # (but see footnote) # Restore the previous instance (and thus the previous value): ON_SCOPE_EXIT { *var= \$nothingToSeeHere::var; }

That is, it is not just the value that is saved, but the scalar that holds that value. This can matter if the variable was tied or has other "magic" attached to it. It also matters if you have taken a reference to the original instance of the variable or take a reference to the new instance (they will point to different variables). It also means that the string value is not copied, as would happen with $saved= $var;.

- tye        

* Actually, this step is less like *var= \undef; (which leaves $var read-only) and perhaps more like *var= do { my $t= undef; \$t };. But testing shows that the latter leaves $var marked "PADBUSY" and "PADMY" so it is perhaps even more like *var= \[undef]->[0];. Go figure. :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://665082]
[marioroy]: why do some posters not know to provide a good SSCCE? Nested loops?
[Corion]: marioroy: Producing good SSCCE is an acquired skill :) You have to produce bad SSCCEs for a long time until you get good. And when you get good, you don't need them that much anymore because you simply isolate the problem and then solve it ;)
[marioroy]: ... and kcott is able to provide something. Amazing.

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2017-08-18 08:15 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (297 votes). Check out past polls.