in reply to Re: Out of Memory in Perl
in thread Out of Memory in Perl

Hi, try wrapping $fh with the <> operator. Otherwise, you just keep setting $line to the $fh object, until you run out of resources.
# wrong while (my $line = $fh){ # right while (my $line = <$fh >){
Additionally, unless you need to process each line individually, it might be simpler to write
open (my $fh, "<", "test.txt"); my @file_array = (<$fh>); print @file_array,"\n";

P.S. Since you are dealing with big files, you might want to use ARGV's special line by line processing magic. That way, you never pull the whole file into memory. Google for perl ARGV magic.

#!/usr/bin/perl use warnings; use strict; # use ARGV's magic @ARGV = "test.txt"; my @results; while ( <ARGV> ){ chomp $_; if ($_ =~ m/head/){ push (@results, $_); } } print "@results\n";

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh