Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Efficient Way to Parse a Large Log File with a Large Regex (with Regexp::Assemble)

by BrowserUk (Pope)
on Apr 13, 2005 at 17:12 UTC ( #447512=note: print w/replies, xml ) Need Help??


in reply to Re: Efficient Way to Parse a Large Log File with a Large Regex (with Regexp::Assemble)
in thread Efficient Way to Parse a Large Log File with a Large Regex

But it will be hugely slower than doing a simple search to find the embedded IP and then look that up in a hash that contains the 500 IPs in question.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco.
Rule 1 has a caveat! -- Who broke the cabal?
  • Comment on Re^2: Efficient Way to Parse a Large Log File with a Large Regex (with Regexp::Assemble)
  • Download Code

Replies are listed 'Best First'.
Re^3: Efficient Way to Parse a Large Log File with a Large Regex (with Regexp::Assemble)
by grinder (Bishop) on Apr 14, 2005 at 09:43 UTC

    It all comes down to the difference between

    /$re/ and print while <>
    and
    while( <> ) { while( /\b(\d+\.\d+\.\d+\.\d+)\b/g ) { if( exists $ip{$1} ) { print; last; } } }

    Hugely slower? No. A quick benchmark here shows that the regular expression appoach is about twice as slow (and we are talking about a problem dominated by disk I/O anyway). One factor depends on how many naked IPs appear on a line. If there are several and only one interests you, the direct regexp will pick it up immediately, whereas the hash approach will have to test each one.

    Another consideration is that if you want to extend the approach to search for e.g. 192.168.0.* then you can no longer use the hash approach at all, since what gets matched does not correspond to any key.

    Or else I completely misread the question, in which case consider my solution withdrawn.

    - another intruder with the mooring in the heart of the Perl

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://447512]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2018-07-19 15:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (411 votes). Check out past polls.

    Notices?