in reply to Re^2: Why do I (sometimes) get a REF ref and not a SCALAR ref?
in thread Why do I (sometimes) get a REF ref and not a SCALAR ref?

Interestingly, using all the expressions in one command:
perl -E 'say for \\$x, \\@x, \\%x;'

gives a different output:

REF(0x1204e78) REF(0x12251f8) REF(0x1225240)

If you don't store the reference, it's freed and reused later.

$ perl -E 'say \\$x; say \\@y; say \\%z;' REF(0xcfae78) REF(0xcfae78) REF(0xcfae78)

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^4: Why do I (sometimes) get a REF ref and not a SCALAR ref?
by kennethk (Abbot) on Jun 23, 2016 at 18:49 UTC
    To finish the set:
    perl -E '@arr=(\\$x,\\@x,\\%x);say \\$x;say \\@x;say \\%x'
    outputs
    REF(0x8e8f58) REF(0x8e8f58) REF(0x8e8f58)
    and
    perl -E '@arr=(\\$x,\\@x,\\%x);say join"\n",\\$x,\\@x,\\%x'
    outputs
    REF(0xdc3f58) REF(0xdc3e38) REF(0xde0618)
    and
    perl -E '@arr=(\\$x,\\@x,\\%x);say $arr[0];say $arr[1];say $arr[2]'
    outputs
    REF(0x19b4d48) REF(0x19b4b98) REF(0x19d13e8)
    I think what's going on is that we're getting the address of a temporary variable. When they are all in the same statement, you need three temporary spots; when in different statements, you just reuse your scratch space.

    Still doesn't answer the 'REF' question, though...


    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.