Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (13)
    As of 2015-07-01 16:56 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (12 votes), past polls