in reply to Out of memory problem when copying contents of file into array

You could try it this way: (for large files)
** Updated to id::1382's suggestion... (is that documented somewhere? ... ***
sub perform { # do per line processing to avoid out-of-memory error. open( FILE, "< ./file.txt" ) or die "Can't open : $!"; while (my $line = <FILE>) { processLine(chomp($line)); } close FILE; } sub processLine { my $line=shift; # etc.
  • Comment on Re: Out of memory problem when copying contents of file into array
  • Download Code

Replies are listed 'Best First'.
Re^2: Out of memory problem when copying contents of file into array
by chromatic (Archbishop) on Feb 19, 2005 at 07:37 UTC

    Unfortunately, for loops build a list out of their contents, which means that the code above will read the entire file into memory. while is the right way to process a line at a time.