in use strict; the behavior of push is predictable, but without -- and using a string in $a[0] -- the behavior is not predictable
Wrong. The behaviour is perfectly predictable. Observe
use Data::Dumper; @a = 'bar'; @bar = 6; warn push @{$a[0]}, 7; warn Dumper( \@a, \@bar ); warn push @{"$a[0]"}, 8; warn Dumper( \@a, \@bar ); warn push @{"bar"}, 9; warn Dumper( \@a, \@bar ); undef $a[0]; warn push @{$a[0]}, 11; warn Dumper( \@a, \@bar ); __END__ 2 at - line 4. $VAR1 = [ 'bar' ]; $VAR2 = [ 6, 7 ]; 3 at - line 7. $VAR1 = [ 'bar' ]; $VAR2 = [ 6, 7, 8 ]; 4 at - line 10. $VAR1 = [ 'bar' ]; $VAR2 = [ 6, 7, 8, 9 ]; 1 at - line 13. $VAR1 = [ [ 11 ] ]; $VAR2 = [ 6, 7, 8, 9 ];

without perl may use the @{$something} as array-ref or variable name... a bit confusing, doesn't it?
Why? Observe
@a = 'bar'; @bar = 6; warn 'PUSHING ONTO @BAR' if defined $a[0]; push @{$a[0]}, 'bar'; undef $a[0]; warn 'PUSHING ONTO $a[0]' if not defined $a[0]; push @{$a[0]}, 'bar'; use Data::Dumper; warn Dumper( \@a, \@bar ); __END__ PUSHING ONTO @BAR at - line 4. PUSHING ONTO $a[0] at - line 10. $VAR1 = [ [ 'bar' ] ]; $VAR2 = [ 6, 'bar' ];

In reply to Re: Re: Re: push undefined and vivification by Anonymous Monk
in thread push undefined and vivification by oha

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.