- I want to read two attached files a1.txt and a2.txt simultaneously.
- I want to get output as mentioned in result.txt file.
- Through my perl code I am able to read a single file.
- Please help me to modify my code to get the desired output.
mtr1amit 0 Newbie Poster
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
-------------------------------------------------------------------
TOTAL 00:47:03
RUN_TIME_FAIL 00:47:31
****************************************************
****************************************************
-------------------------------------------------------------------
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
-------------------------------------------------------------------
TOTAL 00:47:29
RUN_TIME_FAIL 00:48:02
****************************************************
****************************************************
-------------------------------------------------------------------
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
-------------------------------------------------------------------
TOTAL 00:47:02
RUN_TIME_FAIL 00:47:36
****************************************************
****************************************************
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
-------------------------------------------------------------------
TOTAL 00:47:50
RUN_TIME_FAIL 00:48:20
****************************************************
****************************************************
-------------------------------------------------------------------
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
-------------------------------------------------------------------
TOTAL 00:48:09
RUN_TIME_FAIL 00:48:43
****************************************************
****************************************************
-------------------------------------------------------------------
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
-------------------------------------------------------------------
TOTAL 00:48:37
RUN_TIME_FAIL 00:49:08
****************************************************
****************************************************
Test Cases a1 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
mtr1amit 0 Newbie Poster
I am not able to type the code. I have attached my perl code in text file (perfresult.txt)
use strict;
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 );
}
Edited by mtr1amit
mtr1amit 0 Newbie Poster
use strict;
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 );
}
2teez 43 Posting Whiz
Hi,
You didn't tell us that this was also cross-posted in perlmonks Merge columns from two different files and stackoverflow.
2teez 43 Posting Whiz
Hi mtr1amit,
I re-wrote your script to get your required output. However, to arrange the output in your result text file is left for the Original Poster to complete.
Here is the script that generate your required output:
#!/usr/bin/perl
use warnings;
use strict;
my %retrieve = (
1 => q{Retrieve_generic_},
2 => q{Retrieve_assembly_1_},
3 => q{Retrieve_assembly_2_},
4 => q{300_wireframe_view_},
5 => q{80_wireframe_view_},
6 => q{3_hidden_view_},
7 => q{Fast_HLR_},
8 => q{120_hidden_view_},
9 => q{shaded_view_},
10 => q{shaded_mouse_},
11 => q{realtime_rendered_},
);
my $file1 = read_file( 'a1.txt', \%retrieve );
my $file2 = read_file( 'a2.txt', \%retrieve );
print generate_output($file1); # print out match string from file1
print generate_output($file2); # print out match string from file2
sub read_file {
my ( $filename, $matched_data_to_retrieve ) = @_;
my $msg_href = {};
open my $fh, '<', $filename or die "can't open file:$!";
while (<$fh>) {
chomp;
foreach my $matched_str ( keys %{$matched_data_to_retrieve} ) {
if (/$matched_data_to_retrieve->{$matched_str}/) {
my @data_arr = split;
push @{ $msg_href->{ $data_arr[0] } }, $data_arr[1];
}
}
}
return $msg_href;
}
sub generate_output {
my $final_data = shift;
my $msg_string;
foreach ( keys %{$final_data} ) {
$msg_string .= $_;
my $tm;
do {
my $total = 0;
for ( @{ $final_data->{$_} } ) {
my ( $hr, $min, $sec ) = split /:/, $_;
$total += $hr * 3600 + $min * 60 + $sec;
}
my $hms = secondsToHMS( $total / scalar @{ $final_data->{$_} } );
$tm .= $hms . $/;
};
$msg_string .=' ' . $tm;
}
return $msg_string, $/;
}
sub secondsToHMS {
my $seconds = shift;
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 );
}
Hope this help.
Please, if your have some other questions you may also ask.
Thank you
mtr1amit 0 Newbie Poster
Thanks for your reply.
I want to pass a1.txt and a2.txt with their path from command line. Both files are in different directory.May you help me to do it in above code.
Thank you,
2teez 43 Posting Whiz
Hi,
I want to pass a1.txt and a2.txt with their path from command line. Both files are in different directory
Say you are doing this from the Command Line Interface:
perlscript_name.pl directory_to_file_a1.txt directory_to_file_a2.txt
The above directory_to_file_... either of the files are in the array variable @ARGV, so from your code, change Line 19 and 20 from the pervious code which is
my $file1 = read_file( 'a1.txt', \%retrieve );
my $file2 = read_file( 'a2.txt', \%retrieve );
to this:
my $file1 = read_file( $ARGV[0], \%retrieve );
my $file2 = read_file( $ARGV[1], \%retrieve );
that should do.
Edited by 2teez
mtr1amit 0 Newbie Poster
Hi,
I want to parse path of filename that I am passing through command prompt.
e.g e:\perf_result\P-10-20\a1.txt
ARGV[0] and ARGV[1] contains full path including filename.
Here I just want to grep filename a1.txt.
2teez 43 Posting Whiz
Here I just want to grep filename a1.txt.
use File::Basename qw(basename);
my $file_input1 = basename($ARGV[0]); # this gives a1.txt
my $file_input2 = basename($ARGV[1]); # this gives a2.txt
my $file1 = read_file( $file_input1, \%retrieve );
my $file2 = read_file( $file_input2, \%retrieve );
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.