On Mon, Sep 23, 2002 at 11:54:06PM -0600, John Williams wrote: > After testing various cases of x, I came up with one that I cannot > explain. Can someone tell me what is happening here (in perl5)? > > $ perl -le 'print "@{[ $a = ('a','b') x 3 ]}"; print $a' > a bbb > bbb > > or in other words, after evaluating "@a = $a = ('a','b') x 3", > $a is 'bbb' and @a is ('a','bbb') !
Well, Deparse says: $ perl5.6.1 -MO=Deparse -le 'print "@{[ $a = ('a','b') x 3 ]}"; print $a' print "@{[$a = x 3];}"; print $a; -e syntax OK but if I use a nice new perl (where someone, IIRC Rafael Garcia-Suarez, has fixed many many bugs): $ perl5.8.0 -MO=Deparse -le 'print "@{[ $a = ('a','b') x 3 ]}"; print $a' BEGIN { $/ = "\n"; $\ = "\n"; } print "@{[$a = ('a', 'b') x 3];}"; print $a; -e syntax OK and interestingly, perl 5.8.0 gives a different answer from the perl you ran: $ perl5.8.0 -le 'print "@{[ $a = ('a','b') x 3 ]}"; print $a' bbb bbb so I'd say that what you see is a bug, and it's already fixed in 5.8 Nicholas Clark -- Even better than the real thing: http://nms-cgi.sourceforge.net/