in reply to Re^6: Does @{ } copy arrays?
in thread Does @{ } copy arrays?

I suppose there are cases where it's not immediately apparent to the parser if a given occurrence is an lvalue or rvalue?

Perl is very much aware of which expressions should return something "M"odifiable.

$ perl -MO=Concise,-exec -e' $x=$#a ' 2>&1 | grep av2arylen 5 <1> av2arylen sK/1 $ perl -MO=Concise,-exec -e' $#a=$x ' 2>&1 | grep av2arylen 6 <1> av2arylen sKRM*/1 $ perl -MO=Concise,-exec -e' foo($#a) ' 2>&1 | grep av2arylen 6 <1> av2arylen sKM/1 $ perl -MO=Concise,-exec -e' \$#a ' 2>&1 | grep av2arylen 5 <1> av2arylen sKRM/1 $ perl -MO=Concise,-exec -e' 1 for $#a ' 2>&1 | grep av2arylen 7 <1> av2arylen sKM/1 $ perl -MO=Concise,-exec -e' 1 for 0..$#a ' 2>&1 | grep av2arylen 8 <1> av2arylen sK/1

Replies are listed 'Best First'.
Re^8: Does @{ } copy arrays?
by QM (Parson) on Oct 29, 2009 at 16:36 UTC
    Can you provide the decoder ring for things like "sKRM*/1"?

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

      B::Concise lists what opcode flag each letter represents. "M"odifiable is the relevant one here.


      Interesting tidbit:

      As an optimisation, lvalue subs weren't making arylen as Modifiable.

      $ perl -MO=Concise,-exec,f -e'sub f :lvalue { $#a }' 2>&1 | grep av2ar +ylen 4 <1> av2arylen sK/1

      My patch relied on that flag, so it was buggy. The second patch I mentioned made lvalue subs mark arylen as Modifiable.

        OK, I think I understand most of those examples.

        Except foo($#a) has me scratching my head. It's marked modifiable, but it's not a reference (at least not obvious to me). Maybe this is the older, darker magic of the aliasing involved with @_ in subs? (Personally, I avoid coding in such an implicit way, preferring to catch the passed arguments explicitly.)

        I went back an read most of the thread, and, while much of the discussion was over my head, it seems that those in the know are trying to fix it appropriately (or have already done so).

        Thanks to all for a mind-expanding discussion.

        -QM
        --
        Quantum Mechanics: The dreams stuff is made of