我有一个具有这种格式的制表符分隔文件:
Business System Name: OK_CR
Serial Numbr Service Name Program Name Epoch Start Time
------------ -------------------- -------------------- -------------------
GI1001TAA266 PPV 10 (50106) We Bought A Zoo Aug 14 2012 4:15AM
GI1002TB3596 PPV 5 (50101) Help, The (2011) Aug 14 2012 6:30PM
GI1002TDH825 PPV 2 (50098) Safe House Sep 7 2012 2:15AM
Business System Name: OK_SV
Serial Numbr Service Name Program Name Epoch Start Time
------------ -------------------- -------------------- -------------------
GI1001TAA266 PPV 10 (50106) We Bought A Zoo Aug 14 2012 4:15AM
GI1002TB3596 PPV 5 (50101) Help, The (2011) Aug 14 2012 6:30PM
GI1002TDH825 PPV 2 (50098) Safe House Sep 7 2012 2:15AM
我想按日期计算由业务系统标题分隔的行数,我的意思是脚本的结果应该是这样的:
Business System Name: OK_CR
Aug 14: 2
Sep 7: 1
Business System Name: OK_SV
Aug 14: 2
Sep 7: 1
到目前为止,我已经创建了一个哈希,但我对如何计算每个日期并在每个业务系统标头之后重置计数器感到震惊。这是我的脚本:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
open my $fh, '<', 'ppv.txt' or die $!;
my %data;
my $sect;
while (<$fh>) {
next if /^\s+/;
if (/^Business System Name:\s+(\w+)/) {
$sect = $1;
next;
}
#print "$sect\n";
if (defined $sect) {
next if /^Serial Numbr/;
next if /^------------/;
push @{ $data{$sect} }, $_;
}
}
print Dumper \%data;
这是脚本的结果:
$VAR1 = {
'OK_CR' => [
'GI1001TAA266 PPV 10 (50106) We Bought A Zoo Aug 14 2012 4:15AM
',
'GI1002TB3596 PPV 5 (50101) Help, The (2011) Aug 14 2012 6:30PM
',
'GI1002TDH825 PPV 2 (50098) Safe House Sep 7 2012 2:15AM
'
],
'OK_SV' => [
'GI1001TAA266 PPV 10 (50106) We Bought A Zoo Aug 14 2012 4:15AM
',
'GI1002TB3596 PPV 5 (50101) Help, The (2011) Aug 14 2012 6:30PM
',
'GI1002TDH825 PPV 2 (50098) Safe House Sep 7 2012 2:15AM
'
]
};
关于如何从这里前进的任何想法?