Perl 懒惰匹配

Perl 懒惰匹配,第1张

概述[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 懒惰匹配所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1274294.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存