in reply to Efficient log parsing?
You can use substr to constrain the part of the string searched (without replication). And by using the offset of the end of the last capture group you can move the window along the string efficiently:
$s = 'abc' x 10; ## repetative test data $p = 0; ## start at offset 0 ## match against the substring starting at the offset ## and capture (3) items while( my @x = substr( $s, $p ) =~ m[(.)(.)(.)] ) { print "@x"; ## do something with the captures ## and advance the offset to the end of what was matched $p += $+[3]; } a b c a b c a b c a b c a b c a b c a b c a b c a b c a b c
When the while loop exits, the remainder beyond the offset could contain a partial match, so delete the front of the string and append the next read to the end.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Efficient log parsing?
by zrajm (Beadle) on Dec 16, 2007 at 05:12 UTC | |
by zrajm (Beadle) on Dec 17, 2007 at 19:41 UTC |