Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by dave_the_m (Monsignor)
on Dec 06, 2011 at 09:54 UTC ( [id://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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-03-19 07:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found