On Sun, Apr 6, 2008 at 10:36 PM, Richard Lee <[EMAIL PROTECTED]> wrote:
> I am trying to open a big file and go through line by line while limiting
> the resource on the system.
>  What is the best way to do it?
>
>  Does below read the entire file and store them in memory(not good if that's
> the case)..
>
>  open(SOURCE, "/tmp/file") || die "not there: $!\n";
>  while (<SOURCE>) {
>  ## do something
>  }
snip

Unless you are storing the lines you are reading this will only read
one line at a time.  You should also use the new (eight year old)
style lexical filehandles and the three argument version of open:

open my $source, "<", "/tmp/file"
    or die "could not open /tmp/file: $!";
while (my $line = <$source>) {
    #do stuff with $line
}

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to