I'm having a little trouble following the documentation on pushing. It gives us the example:
for $value (LIST) { $ARRAY[++$#ARRAY] = $value; }
I'm assuming (LIST) should be an array list, and if that's so it would have been nice if they said that in the docs because at first I thought it was a filehandle of some kind.
Well first, you should understand the syntax of this kind of generic example first. It is pretty common, throughout the docs, that symbolic representations are represented in upper case. For example, in a regexp
/PATTERN/
"PATTERN" doesn't really represent the upper case word "PATTERN", but any generic regexp pattern. It's something like a variable, for a code template.

In the same way, in the code you brought along, "LIST" is any list. It can be @abc or $a, $b, $c or $a, @b, $c or... Anything, really.

$ARRAY[..] = $value looks like a hash rather than an array so what's really happening?
You must be thinking of PHP. In Perl, hashes are never used in combination with square brackets. So this is a real array, with numerical indexes.

Anyway, "@ARRAY", again, represents any kind of array, for example @{$arrayref}. $#ARRAY is the associated "last index" value of this array. I didn't even know you could use it as an Lvalue, for increment. But, why not. Anyway, what this snippet represents is: increment the size of the array by one, and store the value of $value as the new last array item.

HTH.


In reply to Re: array pushing by bart
in thread array pushing by sulfericacid

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.