That IP regex is not going to work for you. You've got too many capturing groups. (It isn't invalid, it just won't return what you think it does.) As it stands it will return the third digit group and a full stop.

I.E.
my $address = 'ip=111.112.113.114 '; my ($ip) = $address =~ /ip=(([0-1]?[0-9]{1,2}\.)|(2[0-4][0-9]\.)|(25[0 +-5]\.)){3}(([0-1]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))\s/; print $ip;
will print
113.
You would be better off using something like this:
my $tuple = qr'[0-1]?[0-9]{1,2}|2[0-4][0-9]|25[0-5]'; my $address = 'ip=111.112.113.114 '; my ($ip) = $address =~ /ip=(($tuple\.){3}$tuple)\s/; print $ip;
Oh, and I pretty much agree with everything mscharrer said. See my take on it.
#!/usr/bin/perl use warnings; use strict; my %domains; my @domain_array = qw(ebay.com paypal.com americanbank.com usbank.com +americangreetings.com); my @bad_domains; $domains{$_} = undef for @domain_array; my $tuple = qr'[0-1]?[0-9]{1,2}|2[0-4][0-9]|25[0-5]'; open my $log_domain, "logdata" or die "$!\n"; my ($host, $spf, $dkim, $ip); while (<$log_domain>) { ($host) = $_ =~ /domain=([\w\.]+?)\s/;#find regex for domain ($spf) = $_ =~ /spf=([0-4])\s/; #find regex for spf1 ($dkim) = $_ =~ /dkim=([0-4])\s/; #find regex for dkim1 ($ip) = $_ =~ /ip=(($tuple\.){3}$tuple)\s/; if (exists $domains{$host}) { $domains{$host}{counter}++; $domains{$host}{"spf$spf"}++; $domains{$host}{"dkim$dkim"}++; $domains{$host}{ip}{$ip} = undef; } else { push (@bad_domains , $host); } } close ($log_domain); my @stats = qw(dkim0 dkim1 dkim2 dkim3 dkim4 spf0 spf1 spf2 spf3 spf4) +; print "Domain, \"Domain Count\" "; print ucfirst($_).' ' for (@stats, 'IP'); print "\n"; foreach my $host (keys %domains) { print "$host,"; print $domains{$host}{$_} || 0,',' for ("counter",@stats); print keys %{$domains{$host}{ip}} ? (join ',', keys %{$domains{$ho +st}{ip}}) : 'none'; print "\n"; } print "The total amount of domains that we don't care about is ". scal +ar @bad_domains."\n";

In reply to Re: IP Parse and Count from logfile by thundergnat
in thread IP Parse and Count from logfile by indkebr

Title:
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, details, 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, summary, 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.