Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Perhaps the following will assist you in crafting a complete solution:

use strict; use warnings; my %retrieve; my $count = 0; while (<DATA>) { next unless /^Retrieve_/; $count++; my ( $retrieve, $time ) = split; my ( $h, $m, $s ) = split ':', $time; $retrieve{$retrieve} += $h * 3600 + $m * 60 + $s; } for my $retrieve ( keys %retrieve ) { my $hms = secondsToHMS($retrieve{$retrieve} / ( $count / 3 )); print "$retrieve\t$hms\n" if defined $hms; } # For seconds < 86400, else undef returned sub secondsToHMS { my $seconds = $_[0] // 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 ); } __DATA__ perform testing Date: Nov-29-2012 Host: amg Machtype: x86e_win64 mode: 7 ver: 1400 Build : A-01-10 ------------------------------------------------------------------- testcase Version x-20-17 ------------------------------------------------------------------- Retrieve_generic_assembly_(CP) 00:01:20 Retrieve_assembly_1_(CP) 00:01:32 Retrieve_assembly_2_(CP) 00:01:41 ------------------------------------------------------------------- xxx 00:47:03 yyy 00:47:31 ************************************************** ** ************************************************** ** ------------------------------------------------------------------- ggg Version P-20-17 ------------------------------------------------------------------- Retrieve_generic_assembly_(CP) 00:01:25 Retrieve_assembly_1_(CP) 00:01:35 Retrieve_assembly_2_(CP) 00:01:42 ------------------------------------------------------------------- xxx 00:47:03 yyy 00:47:31 ************************************************** ** ************************************************** ** ------------------------------------------------------------------- ggg Version P-20-17 ------------------------------------------------------------------- Retrieve_generic_assembly_(CP) 00:01:25 Retrieve_assembly_1_(CP) 00:01:35 Retrieve_assembly_2_(CP) 00:01:42 ------------------------------------------------------------------- pp 00:47:02 kk 00:47:36 ************************************************** ** ************************************************** **

Output:

Retrieve_assembly_1_(CP) 00:01:34 Retrieve_assembly_2_(CP) 00:01:41 Retrieve_generic_assembly_(CP) 00:01:23

The output shows the average time for each Retrieve_ in p10.txt.

The seconds are continually summed. When the data reading is done, the total seconds are averaged for each Retrieve_, and then printed in H:M:S format.

To process the two files, you could use a construct like this:

$retrieve{$retrieve}{fileName} += $h * 3600 + $m * 60 + $s;

The you could use the subroutine above to calculate both avg H:M:S--including their difference with a prepended minus sign, where appropriate. The last chellenge is to figure out how to print the Retrieve_ lines in your desired order.

Hope this helps!


In reply to Re: Add same columns of a file and then compare two file contents by Kenosis
in thread [untitled node, ID 1007488] by amit1mtr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-20 01:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found