Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

A question on next

0 views
Skip to first unread message

grocery_stocker

unread,
May 8, 2008, 8:19:31 PM5/8/08
to
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{$1} += $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.

A. Sinan Unur

unread,
May 8, 2008, 8:26:51 PM5/8/08
to
grocery_stocker <cda...@gmail.com> wrote in news:42fca2ed-bc46-4c54-
bafa-a43...@x19g2000prg.googlegroups.com:

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).

Sinan

--
A. Sinan Unur <1u...@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

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

grocery_stocker

unread,
May 8, 2008, 8:36:09 PM5/8/08
to
On May 8, 5:26 pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
> grocery_stocker <cdal...@gmail.com> wrote in news:42fca2ed-bc46-4c54-
> bafa-a43e87726...@x19g2000prg.googlegroups.com:

>
> > 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{$1} += $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.
>
> 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).
>
> Sinan
>
> --

Okay, I probably just misunderstood him. Thanks.

xho...@gmail.com

unread,
May 9, 2008, 12:20:54 PM5/9/08
to

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.

Xho

--
-------------------- 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.

0 new messages