Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Search Efficiency

by Cirollo (Friar)
on Jul 11, 2001 at 19:00 UTC ( #95708=note: print w/ replies, xml ) Need Help??


in reply to Search Efficiency

Perl doesn't read in the entire file each time through that loop. Each time through the loop, Perl just reads the next line from the still-opened file.

A few tidbits that might come in handy if you're doing anything more complex:

If you need to know the current line number, look at the $. variable (dollar dot).

The seek function can be used to go to a specific part of a file without reading the whole thing. The tell function returns the current file position in bytes, based at 0.


Comment on Re: Search Efficiency
Re: Re: Search Efficiency
by particle (Vicar) on Jul 11, 2001 at 19:37 UTC
    Cirollo is right. and you want to be careful about where your hash is defined. if it's created inside the while loop, it will be regenerated after every match of the $userid. if it's created outside the while loop, you can add info to it and do your processing after the while loop ends. i suspect this might be the real problem behind your question,

    Is there anyway to tell perl, "hey, you have already gone through x lines, don't start over at the beginning of the file when you loop back through?

    by the way, always use strict and perl -w to keep your code on it's very best behaviour.

    ~Particle

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-12-29 08:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (185 votes), past polls