Monks...

I have a script I'm running, and as part of (the MUCH larger) application, there's a function that takes up so much memory that perl tells me i'm out of it. I've had it working elsewhere (I've modified it slightly and added some things), but need help.

The file I'm processing is REALLY large (hence the line by line read in) -- and when I say large, I'm talking about 500-2400 KB in size.

I've done some debugging and the results are REALLY confusing to me. Everything works fine ... until I get to the last statement of the while loop. I added a print I'm at the end of the while loop-ish statement, and it prints. However, a print I'm out of a while loop-ish statement doesn't print. IT NEVER LEAVES THE LOOP, but stops looping, seemingly.

Here's the code:

sub process_rare_RE { my $file = shift; my $PART3 = 0; my ($sums,$avgs,$ydata,@xdata,@frmt,@values); open(IN,$file) or die "$file failed to open: $!"; ## Reset sums for (0..3) { $sums->[$_] = 0 } while (<IN>) { @values = split /\t/, $_; if ( ($values[4] == 0 && $values[0] >= 2.5) || ($file =~ /Ts21/ && $values[0] == 2.5) ) { $PART3 = 1 } if($PART3) { next if $values[1] < 50; if ($_[0] == 3 || $_[0] == 1) { for (0..2) { $sums->[$_] += $values[$_+1] } $sums->[3]++; } if ($_[0] == 2 || $_[0] == 1) { push @xdata, $values[0]; for (0..2) { push @{$ydata->[$_]}, $values[$_+1] } } } } ## never gets here, hung up above (^) close IN; for (0..$#xdata) { push @frmt, [ $xdata[$_], \@{$ydata} ] } for (0..2) { $avgs->[$_] = $sums->[$_]/$sums->[3] } if ($Debug > 2) { print "\t\tReturn value for process_rare_RE is: \n +", Dumper( ($avgs,\@frmt) ) } return ( $avgs, \@frmt ); }

In reply to Out of memory help by dimmesdale

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.