Perl 懒惰匹配

[grid@devrac1 ~]$ cat sum.pl 
if ( $#ARGV < 0 ){  
        print "please input your file!\n";
        exit(-1);  
    } 
$logfile= $ARGV[0];  
my %log;
open (LOG ,"<","$logfile");
while () {
chomp;
if ($_ =~ /^\[\[seri(.*)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/){
print "\$1 is $1\n";
$var= (split /_/, (split /:/,$_)[2])[0];
$log{$var}++;
}
}
#print  %log;
while(my($ip, $times) = each %log) {
     print "$ip  $times\n";
     }
[grid@devrac1 ~]$ perl sum.pl 1.log
$1 is :288i19BF:122.96.47.8_se[[seri:288i19BF:12
$1 is :288i19BF:122.96.47.8_se[[seri:288i19BF:12
$1 is :288i19BF:122.96.47.8_se[[seri:288i19BF:12
$1 is :288i19BF:192.96.47.8_se[[seri:288i19BF:19
192.96.47.8  1
122.96.47.8  3

你可能感兴趣的:(Perl高级编程)