Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: lexicals are all the same scalar and never go out of scope?

by dave_the_m (Parson)
on Dec 06, 2011 at 09:54 UTC ( #941980=note: print w/ replies, xml ) Need Help??


in reply to lexicals are all the same scalar and never go out of scope?

Your sample code is showing some of the effects of pad temps (SVs_PADTMP flag). The first concat op ("begin". $count++) uses its private pad temporary to generate its result; the second concat just appends to this temp, which is then passed to save(). On subsequent calls, concat reuses the same pad temp, which is why setting it readonly makes your code die.

However, the \ operator has an explicit check that if the thing it's creating a reference to has the SVs_PADTMP flag set, then it makes a copy. Which is why your Data::Dumper output shows four separate values.

Dave.


Comment on Re: lexicals are all the same scalar and never go out of scope?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://941980]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (14)
As of 2014-07-30 19:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (240 votes), past polls