in reply to Re: Efficient log parsing?
in thread Efficient log parsing?

No. That won't work. The loop will only be executed once because of the /g flag, which causes all matches to be returned at once.

Sorry. :(

Replies are listed 'Best First'.
Re^3: Efficient log parsing?
by NetWallah (Canon) on Dec 15, 2007 at 07:05 UTC
    Good catch.

    OK - here is a somewhat contrived variation that seems to work for me:

    use strict; $_="this that other thing that thw tests sometimes"; my $regex = qr/(t..)\w+\s+?(\w\w)(.+)/; my @buffer; my @x; while ( (@x[0..1],$_) = /$regex/) { push @buffer, [ @x ]; print join(",",@x) . ";\n"; }
    Changes:
    • You need to know how many elements to expect
    • The regex has been modified to return all remaining information as the final element
    • The final element gets re-stored into $_
    • No more /g modifier

         "As you get older three things happen. The first is your memory goes, and I can't remember the other two... " - Sir Norman Wisdom