A question on next

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
At work, one of the engineers did something like the following to
parse a 100MB apache log file.

while (<LOG>) {
    next unless (/^\w+\s([a-zA-Z\.]+)\s\w+\s\w+\s\w+\s(\d+)$/);
    $locationhash += $2;


He told me this loop wouldn't check every single in the log file. I
don't see how this is possible. Can someone clarity this? Thank you.

Re: A question on next


Quoted text here. Click to load it

Of course it would check every line in the file. However, it would not
store anything in %locationhash if the match failed.

If you want to parse all of the log file line by line, there is no way
of avoiding loading every line (and most likely, checking every line).


(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc /

Re: A question on next

Quoted text here. Click to load it

Okay, I probably just misunderstood him. Thanks.

Re: A question on next

Quoted text here. Click to load it

What does "check" mean?  The regex will "check" every line.  The hash
will "check" only those lines for which the regex matches (which, for all
I know, might actually be every single line).

The first use of "check" seems more natural to me, but maybe the engineer
intended the second meaning.


-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.

Site Timeline