zrajm has asked for the wisdom of the Perl Monks concerning the following question:
As I go about it right now I have a regular expression matching the beginning of each log entry, with parenthisized subexpressions capturing year, day, month, hour, minute and second of the entry.
I load a chunk of the logfile in question into $_, using sysread. Then I split this into log entries, and subexpressions and put it into an array local to my module. The array looks like this:
[ [ "LOGENTRY 1", $1, $2, $3, $4..], [ "LOGENTRY 2", $1, $2, $3, $4..], ... ]
Each subsequent call to my module's next_entry() simply shifts the top element off the array and return that, until there's only one element left -- then I add another chunk from the logfile, splits that into an array-of-arrays and start the whole circus over again.
However, I'm having some problems in the logfile chunk parsing. Right now, it looks like this:
while (/$regex/g) { push @buffer, [ substr($_, $last, $-[0]-$last), $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, ]; $last = $-[0]; }
At first I tried
while (@x = /($regex)/g) { push @buffer, [ @x ]; }
..but to my suprise that didn't work. Turns out that the m//g in list context returns one list of all subexpressions matched, rather than (as m// without the /g flag) one list of subexpressions per match.
How should I go about this? Perhaps there's some better method that I have completely missed?
P.S. Note that my regex does not match an *entire* log entry, just the beginning of it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Efficient log parsing?
by BrowserUk (Patriarch) on Dec 14, 2007 at 07:38 UTC | |
by zrajm (Beadle) on Dec 16, 2007 at 05:12 UTC | |
by zrajm (Beadle) on Dec 17, 2007 at 19:41 UTC | |
|
Re: Efficient log parsing?
by steved (Initiate) on Dec 14, 2007 at 05:00 UTC | |
by zrajm (Beadle) on Dec 14, 2007 at 07:09 UTC | |
|
Re: Efficient log parsing?
by NetWallah (Canon) on Dec 14, 2007 at 05:54 UTC | |
by zrajm (Beadle) on Dec 14, 2007 at 07:01 UTC | |
by NetWallah (Canon) on Dec 15, 2007 at 07:05 UTC | |
|
Re: Efficient log parsing?
by lihao (Monk) on Dec 14, 2007 at 06:08 UTC |