I'm using strict and warnings for my code, working with data files which can run from 85MB to over 200MB each. After processing is complete on one file, I've been using

splice( @FileData );

to clear the array and release the RAM back to Perl before loading then next file. I understand that this doesn't release the RAM back to the OS; that's fine.

Would using

undef( @FileData );

be a better choice than splice, or just a different one ?

Using either method with a test script, Perl doesn't openly acknowledge the existence of the array after it's been undef'd or spliced. However, it apparently still "exists" because I don't have to redeclare it with

splice( my @FileData );
or
undef( my @FileData );

The commented splice is in the test script because I tried both methods of array declaration; I get the same output either way.
#!C:\Perl\bin use strict; use warnings; my $SampleLine = "Perl is addictive. There should be a warning label +or something\.\.\.\n"; my $Count = 0; #splice( my @TestArray ); undef( my @TestArray ); push( @TestArray, $SampleLine ); $Count = scalar @TestArray; print "\npush Count is $Count\n"; if ( @TestArray ) { print"\nPush - TestArray IS here\n\n"; } else { print"\nAfter Push - TestArray is NOT here\n\n"; } undef( @TestArray ); $Count = scalar @TestArray; print "\nundef Count is $Count\n"; if ( @TestArray ) { print"\nUnDef - TestArray IS here\n\n"; } else { print"\nAfter UnDef - TestArray is NOT here\n\n"; } push( @TestArray, $SampleLine ); $Count = scalar @TestArray; print "\npush Count is $Count\n"; if ( @TestArray ) { print"\nPush - TestArray IS here\n\n"; } else { print"\nAfter Push - TestArray is NOT here\n\n"; } splice( @TestArray ); $Count = scalar @TestArray; print "\nsplice Count is $Count\n"; if ( @TestArray ) { print"\nAfter Splice - TestArray IS here\n\n"; } else { print"\nSplice - TestArray is NOT here\n\n"; }
I'm also wondering if my RAM-clearing step is necessary. I'm loading the data into the array with @FileData = <NEXTFILE>;
Perl allocates more RAM to the array if the next file is larger than the one loaded before it. Does Perl also release RAM from the array if the next file is smaller than the one loaded before it ?
Dyslexics Untie !!!

In reply to arrays : splice or undef ? by JockoHelios

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.