Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://941985]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2017-12-14 23:12 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (414 votes). Check out past polls.