请帮我查找文件中没有出现的内容。还可以找到最大值和最小值。我能找到不存在的事件。
文件
SQL :: select * from person ...etc , Time Taken :: 30
SQL :: select * from emp ...etc , Time Taken :: 5
SQL :: select * from home ...etc , Time Taken :: 20
SQL :: select * from emp ...etc , Time Taken :: 30
SQL :: select * from person ...etc , Time Taken :: 10
SQL :: select * from home ...etc , Time Taken :: 20
SQL :: select * from person ...etc , Time Taken :: 50
输出应为enter code here
SQL No of occu total Min Max
select * from person 3 90 10 50
select * from emp 2 35 5 30
答案 0 :(得分:0)
#!/usr/bin/perl
# sql -> {times, min, max}
my $data = {};
while (<>) {
if (m{SQL.*?(select.*?\.\.\.).*?Taken\s\:\:\s(\d+)}xmsi) {
my ($sql, $time) = ($1, $2);
my $times = $data->{$sql}->{times} || 0;
my $min = $data->{$sql}->{min} || $time;
my $max = $data->{$sql}->{max} || $time;
$max = $time if $time > $max;
$min = $time if $time < $min;
$times++;
$data->{$sql}->{min} = $min;
$data->{$sql}->{max} = $max;
$data->{$sql}->{times} = $times;
}
}
print "SQL No of occu total Min Max\n";
foreach my $sql(sort keys %{$data}) {
print "$sql $data->{$sql}->{times} total $data->{$sql}->{min} $data->{$sql}->{max}\n";
}
运行:
stat.pl <your data file>
自己添加。