Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners > Re: opening a b...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 10884 of 11982
Post > Topic >>

Re: opening a big file

by chas.owens@[EMAIL PROTECTED] (Chas. Owens) Apr 6, 2008 at 11:05 PM

On Sun, Apr 6, 2008 at 10:36 PM, Richard Lee <rich.japh@[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 im****tant skill a programmer can have is the ability to read.
 




 1 Posts in Topic:
Re: opening a big file
chas.owens@[EMAIL PROTECT  2008-04-06 23:05:24 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Oct 10 15:05:22 CDT 2008.