I am also running out of memory before the loop completes.

What is your idea of $aref in that loop that bombs off? Is it an integer, or an array reference? What it the result of adding 1 to an array reference? or 2 ? What happens to an array (or array reference) if you index it with the result of that addition?

my $aref = []; print $aref,"\n"; print $aref + 1,"\n"; print $aref + 2,"\n"; print "mem: ",qx{ps -o vsz= $$}; $aref[$aref +2] = "foo"; print "mem: ",qx{ps -o vsz= $$}; __END__ ARRAY(0xf5dba0) 16112545 16112546 mem: 28964 mem: 154844

By converting the hexadecimal address of $aref to integer - this is what happens if you add an integer to it - and using it then as an index, you extend @data and pre-allocate slots, each containing a NULL value. If the address of $aref is high enough, your program hits the memory limit of your machine.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

In reply to Re: Running out of memory while running this for loop by shmem
in thread Running out of memory while running this for loop by Ppeoc

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.