我编写了以下 perl 代码来读取文本文件(a1.txt)并平均时间戳。我想同时读取两个文件(a1.txt 和 a2.txt)并合并两个文件中的所有列。
下面的代码一次只能读取一个文件。请帮我修改下面的 Perl 代码并以下列格式给出输出。
a1.txt
:
PERFORMANCE TESTING
-------------------------------------------------------------------
PERF_SMK_OCUS_50 Version P-20-17
-------------------------------------------------------------------
300_wireframe_view_redraws_(GR) 00:01:56
80_wireframe_view_redraws_with_DATUMS_on_(GR) 00:00:51
3_hidden_view_redraws_(GR) 00:01:35
6_Fast_HLR_activations_(CP) 00:01:10
120_hidden_view_redraws_with_Fast_HLR_(GR) 00:00:42
2_shaded_mouse_spins_(GR) 00:00:21
270_shaded_view_redraws_(GR) 00:01:39
-------------------------------------------------------------------
****************************************************
****************************************************
-------------------------------------------------------------------
PERF_SMK_OCUS_50 Version P-20-17
-------------------------------------------------------------------
300_wireframe_view_redraws_(GR) 00:01:56
80_wireframe_view_redraws_with_DATUMS_on_(GR) 00:00:51
3_hidden_view_redraws_(GR) 00:01:35
6_Fast_HLR_activations_(CP) 00:01:09
120_hidden_view_redraws_with_Fast_HLR_(GR) 00:00:42
2_shaded_mouse_spins_(GR) 00:00:20
270_shaded_view_redraws_(GR) 00:01:39
-------------------------------------------------------------------
****************************************************
****************************************************
-------------------------------------------------------------------
PERF_SMK_OCUS_50 Version P-20-17
-------------------------------------------------------------------
300_wireframe_view_redraws_(GR) 00:01:55
80_wireframe_view_redraws_with_DATUMS_on_(GR) 00:00:50
3_hidden_view_redraws_(GR) 00:01:34
6_Fast_HLR_activations_(CP) 00:01:09
120_hidden_view_redraws_with_Fast_HLR_(GR) 00:00:40
2_shaded_mouse_spins_(GR) 00:00:21
270_shaded_view_redraws_(GR) 00:01:35
-------------------------------------------------------------------
****************************************************
****************************************************
a2.txt
:
PERFORMANCE TESTING
-------------------------------------------------------------------
PERF_SMK_OCUS_50 Version P-20-17
-------------------------------------------------------------------
80_wireframe_view_redraws_with_DATUMS_on_(GR) 00:00:50
3_hidden_view_redraws_(GR) 00:01:37
6_Fast_HLR_activations_(CP) 00:01:12
120_hidden_view_redraws_with_Fast_HLR_(GR) 00:00:43
2_shaded_mouse_spins_(GR) 00:00:21
270_shaded_view_redraws_(GR) 00:01:35
240_realtime_rendered_redraws_(GR)_1 00:13:16
-------------------------------------------------------------------
****************************************************
****************************************************
-------------------------------------------------------------------
PERF_SMK_OCUS_50 Version P-20-17
-------------------------------------------------------------------
80_wireframe_view_redraws_with_DATUMS_on_(GR) 00:00:50
3_hidden_view_redraws_(GR) 00:01:37
6_Fast_HLR_activations_(CP) 00:01:12
120_hidden_view_redraws_with_Fast_HLR_(GR) 00:00:42
2_shaded_mouse_spins_(GR) 00:00:20
270_shaded_view_redraws_(GR) 00:01:40
240_realtime_rendered_redraws_(GR)_1 00:13:14
-------------------------------------------------------------------
****************************************************
****************************************************
-------------------------------------------------------------------
PERF_SMK_OCUS_50 Version P-20-17
-------------------------------------------------------------------
80_wireframe_view_redraws_with_DATUMS_on_(GR) 00:00:50
3_hidden_view_redraws_(GR) 00:01:37
6_Fast_HLR_activations_(CP) 00:01:12
120_hidden_view_redraws_with_Fast_HLR_(GR) 00:00:44
2_shaded_mouse_spins_(GR) 00:00:20
270_shaded_view_redraws_(GR) 00:01:40
240_realtime_rendered_redraws_(GR)_1 00:13:24
-------------------------------------------------------------------
****************************************************
****************************************************
期望的输出:
> Test Cases a1.txt timestamp (hh:mm:ss) a2.txt(hh:mm:ss) delta (a1 -a2)(hh:mm:ss)
>----------------------------------------------------------------------------------------------------------------
>240_realtime_rendered_redraws_(GR)_1 N/A 00:13:18 N/A
> 3_hidden_view_redraws_(GR) 00:01:34 00:01:37 -00:00:03
> 270_shaded_view_redraws_(GR) 00:01:37 00:01:38 -00:00:01
> 120_hidden_view_redraws_with_Fast_HLR_(GR) 00:00:41 00:00:43 -00:00:02
> 300_wireframe_view_redraws_(GR) 00:01:55 N/A N/A
> 2_shaded_mouse_spins_(GR) 00:00:20 00:00:20 00:00:00
> 6_Fast_HLR_activations_(CP) 00:01:09 00:01:12 -00:00:03
> 80_wireframe_view_redraws_with_DATUMS_on_(GR) 00:00:50 00:00:50 00:00:00
我的代码:
my %retrieve;
my $count = 0;
my $file1 = 'a1.txt';
open (R, $file1) or die ("Could not open $file1!");
while (<R>) {
next unless /^*Retrieve_generic_/ ||
/^*Retrieve_assembly_1_/ ||
/^*Retrieve_assembly_2_/ ||
/^*300_wireframe_view_/ ||
/^*80_wireframe_view_/ ||
/^*3_hidden_view_/ ||
/^*Fast_HLR_/ ||
/^*120_hidden_view_/ ||
/^*shaded_view_/ ||
/^*shaded_mouse_/ ||
/^*realtime_rendered_/;
$count++;
my ( $retrieve, $time ) = split;
my ( $h, $m, $s ) = split ':', $time;
$retrieve{$retrieve} += $h * 3600 + $m * 60 + $s;
}
close(R);
for my $retrieve ( keys %retrieve ) {
my $hms = secondsToHMS($retrieve{$retrieve} / ( 3));
print "$retrieve\t$hms\n" if defined $hms;
}
# For seconds < 86400, else undef returned
sub secondsToHMS {
my $seconds = $_[0];
return undef if $seconds >= 86400;
my $h = int $seconds / 3600;
my $m = int( $seconds - $h * 3600 ) / 60;
my $s = $seconds % 60;
return sprintf( '%02d:%02d:%02d', $h, $m, $s );
}