概述[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 (<LOG>) { chom [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 (<LOG>) { chomp; if ($_ =~ /^\[\[seri(.*)(\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 这里直接贪婪的
匹配到了:288i19BF:192.96.47.8_se[[seri:288i19BF:19 ----------------------------------------------------------------- [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 (<LOG>) { chomp; if ($_ =~ /^\[\[seri(.*?)(\d{1,$times) = each %log) { print "$ip $times\n"; } [grID@devrac1 ~]$ perl sum.pl 1.log $1 is :288i19BF: $1 is :288i19BF: $1 is :288i19BF: $1 is :288i19BF: 192.96.47.8 1 122.96.47.8 3 这里匹配到第一个就停止了 [grID@devrac1 ~]$ cat 1.log [[seri:288i19BF:122.96.47.8_se[[seri:288i19BF:122.96.47.8ssionID: [[seri:288i19BF:122.96.47.8_se[[seri:288i19BF:122.96.47.8ssionID: [[seri:288i19BF:122.96.47.8_se[[seri:288i19BF:122.96.47.8ssionID: [[seri:288i19BF:192.96.47.8_se[[seri:288i19BF:192.96.47.8ssionID: 总结
以上是内存溢出为你收集整理的Perl 懒惰匹配全部内容,希望文章能够帮你解决Perl 懒惰匹配所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
评论列表(0条)