in reply to Amazing syntax of push (was Re: Removing duplicates in Array of Array)
in thread Removing duplicates in Array of Array

The seemingly obvious reasons that I can come up with are (a) either array in push @{ @p } , ... is magically being used as an array reference; (b) or the array deference is being optimized out. Given ...

use warnings; use strict; my @p; my $p = \@p; push @p , [ 1 , 2 ]; push @{ $p } , [ 3 , 4 ]; push @{ @p } , [ 5 , 6 ];

... output of perl -MO=Terse file (5.8.8; in case somebody can make more sense of it than I can) ...

LISTOP (0x875ffa8) leave [1] OP (0x86ed188) enter COP (0x86ed748) nextstate OP (0x87255e0) padav [1] COP (0x8722170) nextstate BINOP (0x8760098) sassign UNOP (0x872ec78) refgen UNOP (0x8760020) null [141] OP (0x872ff90) pushmark OP (0x873a360) padav [1] OP (0x873b480) padsv [2] COP (0x86f4b28) nextstate LISTOP (0x87605c0) push [3] OP (0x8724410) pushmark OP (0x86ed670) padav [1] UNOP (0x87244d0) srefgen UNOP (0x8760188) null [141] LISTOP (0x8760110) anonlist OP (0x8728370) pushmark SVOP (0x872a238) const [8] IV (0x8753ef8) 1 SVOP (0x872fec8) const [9] IV (0x8753eec) 2 COP (0x86d7c40) nextstate LISTOP (0x8761420) push [5] OP (0x86f5a00) pushmark UNOP (0x8722228) rv2av [4] LISTOP (0x8760638) scope OP (0x86edc08) null [174] OP (0x87223a8) padsv [2] UNOP (0x86f58d0) srefgen UNOP (0x8761270) null [141] LISTOP (0x8760a58) anonlist OP (0x86f5058) pushmark SVOP (0x86f5430) const [10] IV (0x8753ebc) 3 SVOP (0x86f5098) const [11] IV (0x8753eb0) 4 COP (0x8736298) nextstate LISTOP (0x87615e0) push [7] OP (0x8711da0) pushmark UNOP (0x86f3990) rv2av [6] LISTOP (0x87618c8) scope OP (0x87361b8) null [174] OP (0x86f7370) padav [1] UNOP (0x8711c78) srefgen UNOP (0x8761728) null [141] LISTOP (0x8761b38) anonlist OP (0x86f3ba0) pushmark SVOP (0x86f3f10) const [12] IV (0x8753e8c) 5 SVOP (0x86f3fc0) const [13] IV (0x8753e80) 6

perl 5.8.8 & 5.10.0 did not have any problems in parsing the code.

Replies are listed 'Best First'.
Re^2: Amazing syntax of push (was Re: Removing duplicates in Array of Array)
by ikegami (Patriarch) on Sep 04, 2008 at 08:31 UTC

    rv2av doesn't seem to care whether it gets an array reference or an array.

    Update: This is confirmed by BrowserUK's less specific test and by looking at the 5.8.8 source:

    PP(pp_rv2av) { ... if (SvROK(sv)) { ... av = (AV*)SvRV(sv); ... } else { if (SvTYPE(sv) == SVt_PVAV) { av = (AV*)sv; ... } ... } ... ...return something derived from av... }