Assigning anonymous hash to a list

Abigail abigail at abigail.be
Tue Jul 30 20:49:35 BST 2013


On Tue, Jul 30, 2013 at 03:34:48PM -0400, Joseph Werner wrote:
> I disagree.
> 
> This is a straightforward  assignment to the first element of a list.
> Precedence is not involved. A scalar assignment vs a list assignment
> is the issue.
> 


Thank you for playing.


You are right it's straighforward, but you're wrong that it's scalar
assignment vs list assignment. 

The fact there's "my ($str, $ref)" on the LHS of the assignment makes
that Perl considers this a list assignment:


  $ perl -MO=Terse -e 'my ($str, $ref) = "text", {a => 1, b => 2, c => 3}'
  LISTOP (0x100324de0) leave [1] 
      OP (0x100324e20) enter 
      COP (0x100324d90) nextstate 
      LISTOP (0x100301f10) list 
          OP (0x100301ee0) pushmark 
          BINOP (0x1003093c0) aassign [3] 
              UNOP (0x100309950) null [148] 
                  OP (0x100309390) pushmark 
                  SVOP (0x100309d90) const  PV (0x1008143c0) "text" 
              UNOP (0x100329530) null [148] 
                  OP (0x100329570) pushmark 
                  OP (0x1003096e0) padsv [1] 
                  OP (0x100309600) padsv [2] 
          LISTOP (0x100309460) anonhash 
              OP (0x1003094a0) pushmark 
              SVOP (0x100309400) const  PV (0x100814408) "a" 
              SVOP (0x100309430) const  IV (0x1008143f0) 1 
              SVOP (0x1003094d0) const  PV (0x100814048) "b" 
              SVOP (0x100309500) const  IV (0x1008143a8) 2 
              SVOP (0x100309530) const  PV (0x100814378) "c" 
              SVOP (0x100309560) const  IV (0x100814390) 3 
  -e syntax OK
  $


Note the line: BINOP (0x1003093c0) aassign [3], and compare:

  $ perl -MO=Terse -e 'my ($str, $ref) = ("text", {a => 1, b => 2, c => 3})'
  LISTOP (0x100324d90) leave [1] 
      OP (0x100324dd0) enter 
      COP (0x100324d40) nextstate 
      BINOP (0x100309570) aassign [3] 
          UNOP (0x100301f10) null [148] 
              OP (0x100301ee0) pushmark 
              SVOP (0x100309d90) const  PV (0x1008143c0) "text" 
              LISTOP (0x1003093c0) anonhash 
                  OP (0x100309400) pushmark 
                  SVOP (0x100309950) const  PV (0x100814450) "a" 
                  SVOP (0x100309390) const  IV (0x100814408) 1 
                  SVOP (0x100309430) const  PV (0x1008143f0) "b" 
                  SVOP (0x100309460) const  IV (0x100814048) 2 
                  SVOP (0x100309490) const  PV (0x1008143a8) "c" 
                  SVOP (0x1003094c0) const  IV (0x100814378) 3 
          UNOP (0x100329530) null [148] 
              OP (0x100329570) pushmark 
              OP (0x1003096e0) padsv [1] 
              OP (0x100309600) padsv [2] 
  -e syntax OK
  $



Abigail


More information about the london.pm mailing list