Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^8: Shouldn't references be readonly?

by Fletch (Bishop)
on Aug 05, 2020 at 21:16 UTC ( #11120363=note: print w/replies, xml ) Need Help??


in reply to Re^7: Shouldn't references be readonly? (updated)
in thread Shouldn't LITERAL references be readonly? (updated)

The undef $_++ vs $$_++ I think the former is working because what's happening is:

  • An SVrv pointing to the SV* for undef is pushed on the arg stack
  • When map calls the EXPR $_++ that reference is getting numified, incremented, and that new int value stuck back into the SV* on the arg stack
  • Since it's a postincrement the map is returning the original value of $_ which is the ref to undef
  • The call stack goes away and with it the SV* which had the numified address plus one.

In the second case you're explicitly dereferencing the SVrv to the constant undef and trying to increment that (which fails because undef is a singleton readonly SV*).

Edit: And again yes making explanation by way of the implementation, but I think that's because knowing (sort of) how this is implemented under the covers makes these particular corner cases' behaviors not (as) surprising.

The cake is a lie.
The cake is a lie.
The cake is a lie.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2023-03-23 07:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (60 votes). Check out past polls.

    Notices?