in reply to Efficient Way to Parse a Large Log File with a Large Regex

Doesn't this cry for a hash-lookup?
use strict; my @ips = ( "192.1.20.1", "192.1.20.2", ); my %ips = map { $_=>1 } @ips; open LOG, "<", "logfile" or die $!; while ( <LOG> ) { #match ip-address if ( /(([0-9]+\.)+[0-9]+)/ ) { if ( $ips{$1} ) { # do found ip stuff here } else { #do other stuff here } } } close LOG;


holli, /regexed monk/

Replies are listed 'Best First'.
Re^2: Efficient Way to Parse a Large Log File with a Large Regex
by Grygonos (Chaplain) on Apr 12, 2005 at 20:38 UTC

    That and a dispatch table possibly..especially if you have specific logging/functions you want to happen for certain IP addresses.