in reply to Re: How to parse a file with emails and IP's and output a sorted list with a total count
in thread How to parse a file with emails and IP's and output a sorted list with a total count

Bareword found where operator expected at line 24, near "s/\@.*//r"

print $who =~ s/\@.*//r, " total: ", scalar @ips, " unique ip's\n";

I took out the single quote, and still same thing. What's the bare word it is complaining about. I think it doesn't like $who in that case..

  • Comment on Re^2: How to parse a file with emails and IP's and output a sorted list with a total count
  • Download Code

Replies are listed 'Best First'.
Re^3: How to parse a file with emails and IP's and output a sorted list with a total count
by Anonymous Monk on Jul 28, 2016 at 23:33 UTC

    You probably have an older perl that does not understand the /r

    Here's an alternate...

    #!/usr/bin/perl -l # http://perlmonks.org/?node_id=1168769 use strict; use warnings; my %ips; while(<DATA>) { /.* (\S+):(\S+)$/ or next; $ips{$1}{$2}++; } for my $who ( sort keys %ips ) { print $who; my @ips; for my $ip ( @ips = sort keys %{ $ips{$who} } ) { print "=> $ip ($ips{$who}{$ip})"; } print $who =~ /(.*?)\@/, " total: ", scalar @ips, " unique ip's\n"; } __DATA__ Jul 28 13:42:27 mail vpopmail[47985]: vchkpw-smtp: (PLAIN) login succe +ss joe@example.com:192.168.250.251 Jul 28 13:42:28 mail vpopmail[47992]: vchkpw-smtp: (PLAIN) login succe +ss joe@example.com:192.168.5.23 Jul 28 13:42:29 mail vpopmail[47994]: vchkpw-smtp: (PLAIN) login succe +ss sally@example.com:192.168.10.28 Jul 28 13:42:27 mail vpopmail[47985]: vchkpw-smtp: (PLAIN) login succe +ss fred@example.com:192.168.8.8 Jul 28 13:42:28 mail vpopmail[47992]: vchkpw-smtp: (PLAIN) login succe +ss joe@example.com:192.168.5.23 Jul 28 13:42:29 mail vpopmail[47994]: vchkpw-smtp: (PLAIN) login succe +ss harry@example.com:192.168.10.5