Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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 lurking in the Monastery: (9)
As of 2014-12-26 11:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls