in reply to Re: Out of Memory in Perl
in thread Out of Memory in Perl
Additionally, unless you need to process each line individually, it might be simpler to write# wrong while (my $line = $fh){ # right while (my $line = <$fh >){
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";
|
|---|