Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Efficient Way to Parse a Large Log File with a Large Regex

by holli (Abbot)
on Apr 12, 2005 at 20:07 UTC ( [id://447155]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://447155]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (1)
As of 2024-04-25 03:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found