sulfericacid,
From perldoc -f push:
push ARRAY,LIST Treats ARRAY as a stack, and pushes the values of LIST onto the end of + ARRAY. The length of ARRAY increases by the length of LIST. Has the +same effect as for $value (LIST) { $ARRAY[++$#ARRAY] = $value; } but is more efficient. Returns the new number of elements in the array +.
Ok - you completely missed the part that says same effect as. The syntax for push is (see top line of documentation):
push @array , "new value";
The blurb from the documentation is saying that push treats the array like a stack. Imagine one of those bad cafeteria's that have the plates on a spring loaded stack. You push a new plate onto the stack it gets bigger, you pop one off by pulling the top plate off.

This example of code is doing the following:

  • For each item in a list (any list not just array), treat each item as $value
  • Find the last element of the array using $#ARRAY, and one to it with ++, and set that equal to $value
  • As a side effect, it returns the new number of elements in the array ( $newcount = push @array , "blah" ), you would get the total number of elements in the array

    That is the same thing as pushing a new plate on the stack.

    I hope this helps - L~R


    In reply to Re: array pushing by Limbic~Region
    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.