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 ikegami (Pope)
on Dec 06, 2011 at 10:08 UTC ( #941985=note: print w/ replies, xml ) Need Help??


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

First, you keep talking about my and lexical vars, but the only two lexical vars are $count and @savearr, but your question has nothing to do with either. I have no idea why you keep mentioning them. Of course, that means your ultimate question makes no sense.

Second, your references are to different scalars. As you said, how else can they have different values as shown in the dump.

So on to the interesting bit, what is it you're making read-only, and why does it have that effect.

Each instance of the concatenation operator has a scalar called "TARG" associated with it. The concatenation operator concatenates its operands into its TARG, and it returns its TARG. This is an optimisation, as it saves the operator from making a new scalar every time it's called. You made that scalar read-only, messing with the concatenation operator's ability to change it the next time it is called.

So how come you end up with references to different scalars? The dereference operator must know something is special about the scalar*, makes a copy of it, and returns a reference to the copy.

* — I was hoping to provide more details about this, but I've run out of time. I'm guessing it's based on the presence of the PADTMP flag.


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2014-07-24 23:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (167 votes), past polls