Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

as mentioned above use seek so you don't re read the log. Either qr/ / a series of regex into an array and for it or if you can swiftly split out the IP from the log i.e. if they all apear in the same position on a line you can use unpack to extract the IP and something like this may help. Even more so if your desired IPs cluster a bit in the class A octet

#!/usr/bin/perl use strict; use warnings; $>++; # get 500 random ip adresses, see genip code below my %need; open IP, "./genip |" or die "ooeps $!\n"; for (1..500) { my ($a, $b, $c, $d)=split /\./, <IP>; $need{$a}{$b}{$c}{$d}++; } for (1..10_000_000) { my $ip=<IP>; my ($a, $b, $c, $d)=split /\./, $ip; # the compiler may optimise this line ... # next unless exists $need{$a}{$b}{$c}{$d}; # so all the following can probably be replaced # but it is too late for me to benchmark, g'night next unless exists $need{$a}; next unless exists $need{$a}{$b}; next unless exists $need{$a}{$b}{$c}; print "a.b.c\n"; # see how sparse we are ! next unless exists $need{$a}{$b}{$c}{$d}; print "match ! $ip\n"; } close IP; __END__ # Random IP address generator used above ... #!/usr/bin/perl use strict; use warnings; while (1) { my $ip = int rand 256; for (1..3) { $ip.= "." . int rand 256; } print $ip, $/; }
To get any hits I upped the searched for IPs to 5000 then saw a few in reaonable time


Pereant, qui ante nos nostra dixerunt!

In reply to Re: Efficient Way to Parse a Large Log File with a Large Regex by Random_Walk
in thread Efficient Way to Parse a Large Log File with a Large Regex by Dru

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (7)
    As of 2018-07-18 11:02 GMT
    Find Nodes?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

      Results (389 votes). Check out past polls.