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 );
I'm also wondering if my RAM-clearing step is necessary. I'm loading the data into the array with @FileData = <NEXTFILE>;#!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"; }
In reply to arrays : splice or undef ? by JockoHelios
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |