+ -
当前位置:首页 → 问答吧 → 帮我看下我这程序中哪部分影响效率,谢谢

帮我看下我这程序中哪部分影响效率,谢谢

时间:2010-09-15

来源:互联网

这比awk还慢,我想perl 应该不至于吧,麻烦帮我看下我这程序中哪部分影响效率,谢谢


use File::Find;
#!/usr/bin/perl -w
use strict;
my %hash;
my $date =  $ARGV[0];
        my $systm ;
sub scan {
        #$File::Find::name带绝对路径
        #$_ 只有文件名
        if($_ =~ /.*$date.*log/) {  #如果是普通文件
                open(FH,$_) or die $!;
                while(my $line=<FH>) {
                        my @line_arr = split(/\,/,$line);
                        my $forth;
                        if($line_arr[1] =~ /$systm/ && $line_arr[0] =~ /CCA/ && $line_arr[0] =~ /$date/) {
                                 $forth = $line_arr[3];  # 存放第四列
                        }
                        my @forth_arr = split(/\|/,$forth);
                        if($forth_arr[1] =~ /[0-9]+/) {
                        $hash{$forth_arr[1]} ++;
                        }
                }
               
        }
        close(FH);
               
}
       
$systm = "epdscp1";
find(\&scan, "/ocslog/logs/dccproxy_logs/ggsnhw_logs");
scan_print("ggsn");
init();
$systm = "epdscp[1-2]";
find(\&scan , "/ocslog/logs/dccproxy_logs/eggsn_logs");
scan_print("eggsn");
init();
$systm = "egprs[1-2]";
find(\&scan , "/ocslog/logs/dccproxy_logs/vac_logs");
scan_print("vac");

#打印
sub scan_print {
        my $name = shift;
        foreach (keys %hash) {
                if($hash{$_}) {
                        print("$name\t$_\t".$hash{$_}."\n");
                }
                }
                print("\n");
        }

#将hash初始化               
sub init {
                foreach (keys %hash) {
                        $hash{$_} = 0;
                }
        }

作者: xidianmhb   发布时间: 2010-09-15

awk -F \, '{if ($1~/CCA/ &&$2~/epdscp1/&&$1~/20100913/) print $4}' *20100913*log|awk -F \| '{print $2}'|sort| uniq -c

awk语句是这样的

作者: xidianmhb   发布时间: 2010-09-15