Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Ref to a list not being equivalent to a list of refs to each element

by Errto (Vicar)
on Jun 22, 2006 at 18:23 UTC ( [id://556979]=note: print w/replies, xml ) Need Help??


in reply to Ref to a list not being equivalent to a list of refs to each element

A related quirk I ran across earlier, and which I also am not sure is documented (though I may have missed it), is that references to literal strings are read-only, but references to computed strings, including interpolated literals, are not. For example
my $x = 'foo'; my $y = \"bar$x"; $$x = 'baz';
does not throw any errors or warnings. Does anyone know why exactly that is?
  • Comment on Re: Ref to a list not being equivalent to a list of refs to each element
  • Download Code

Replies are listed 'Best First'.
Re^2: Ref to a list not being equivalent to a list of refs to each element
by broquaint (Abbot) on Jun 23, 2006 at 17:26 UTC
    This occurs for the same reasons given above as
    \"foo";
    creates a references to a constant value whereas
    \"foo$x";
    is creating a reference to a temporary value.

    If you want to see the evidence then just put Devel::Peek to work (take note of the FLAGS values for the reference):

    use Devel::Peek; my $x = 'foo'; Dump \'foo'; Dump \"bar$x"; __output__ SV = RV(0x183c90c) at 0x225fe4 REFCNT = 1 FLAGS = (PADBUSY,PADTMP,ROK,READONLY) RV = 0x225ffc SV = PV(0x22626c) at 0x225ffc REFCNT = 1 FLAGS = (POK,READONLY,pPOK) PV = 0x1831d04 "foo"\0 CUR = 3 LEN = 4 SV = RV(0x183c92c) at 0x2252ac REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x225150 SV = PV(0x2261a0) at 0x225150 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x1831cac "barfoo"\0 CUR = 6 LEN = 7
    HTH

    _________
    broquaint

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-23 16:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found