Further to davido's discussion of the Perl interpreter's efforts to manage memory for your arrays (and hashes and everything else):
geertvc: Note that if you have an array that starts small and that will grow to a very large size that you know (or can estimate) in advance, it's possible and occasionally advantageous to "pre-grow" the array by assignment to the array's max index via the  $# array dereference operator (if that's the correct terminology).

c:\@Work\Perl\monks>perl -wMstrict -le "my @ra = qw(a b c); print 'A: array max index: ', $#ra; ;; $#ra += 1_000_000; print 'B: array maximum index: ', $#ra; print 'B: number of array elements: ', scalar @ra; " A: array max index: 2 B: array maximum index: 1000002 B: number of array elements: 1000003
See perldata regarding $#. In most cases, however, it's best to let the interpreter manage these things on its own.


Give a man a fish:  <%-{-{-{-<


In reply to Re: Adding items to arrays: best approach? by AnomalousMonk
in thread Adding items to arrays: best approach? by geertvc

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.