Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: out of memory error while reading file contents into an array

by tokpela (Chaplain)
on Aug 11, 2009 at 14:03 UTC ( #787634=note: print w/ replies, xml ) Need Help??


in reply to out of memory error while reading file contents into an array

You should iterate over the filehandle directly.

use strict; use warnings; my $filename = 'filename.txt'; open(my $fh, $filename) or die "cann't open file filename : $!\n"; while (<$fh>) { my $line = $_; next if ($line =~ /^\s*$/); # skip blank lines chomp($line); # remove line endings # .... do your coding here on each line } close($fh);


Comment on Re: out of memory error while reading file contents into an array
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://787634]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2015-07-06 19:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (81 votes), past polls