- 论坛徽章:
- 0
|
Before
real 0m1.344s
user 0m1.752s
sys 0m0.953s
Now:
real 0m0.188s
user 0m0.124s
sys 0m0.061s
#!/usr/bin/perl -w
use strict;
my $fileone=$ARGV[0];
my $filetwo=$ARGV[1];
print $fileone;
my (@id,@res,@contents);
my $result;
open (FH,$fileone);
while(<FH>){
chomp;
push (@id,$_);
#print "$_\t$result\n";
}
close FH;
open (FH,$filetwo);
@contents = <FH>;
close FH;
foreach my $name(@id){
print $name;
#@res = `grep -c $name $filetwo`; # system是shell返回值,不是返回结果。最好是把文件保存到内存,然后用perl中的grep 去查询,用shell好像慢了点
my $count = grep /$name/, @contents;
print "\n$count\n";
} |
|