Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^3: Don't re-read file for each new pattern...

by scorpio17 (Monsignor)
on May 30, 2007 at 14:57 UTC ( #618200=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Don't re-read file for each new pattern...
in thread Don't re-read file for each new pattern...

It's pretty common to see scripts process files one line at a time. So you have code like this:

open FILE, $filename or die "cant open: $!"; while(<FILE>) { chomp; print "read line: $_ \n"; } close FILE;
This loop will iterate once for each line of the file. The instruction "Don't re-read the file..." means don't put a loop like this inside the infinite while(1) loop. Instead, you read all the lines (once) and save them in the @strings array. This is more efficient, because memory access is faster than file I/O.


Comment on Re^3: Don't re-read file for each new pattern...
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2014-07-26 15:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (178 votes), past polls