in reply to Re: Out of Memory in Perl
in thread Out of Memory in Perl
Your problem is (potentially) two-fold: with this snippet you are tying to read the entire file into memory (but actually, you are getting stuck in a neverending while loop because you use $fh instead of <$fh>). Are you doing something special with this that requires the entire file to be read in at once or just printing it to STDOUT (or another file handle)? If the latter, a simple fix is:
open my $fh, "<", "Google_1.txt"; print $_ while <$fh>;
One more thing... If the input file is small enough and you really do want to read it into an array for something other than printing, you can use something like this instead of your while loop:
open my $fh, "<", "Google_1.txt"; my @file_array = <$fh>; chomp @file_array;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Out of Memory in Perl
by maheshkumar (Sexton) on Jul 09, 2012 at 00:23 UTC | |
by frozenwithjoy (Priest) on Jul 09, 2012 at 00:27 UTC |