Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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 ************************************************** ** ************************************************** **


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

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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?

    What's my password?
    Create A New User
    [Lady_Aleena]: I don't want to have to do: alpha_menu($hash, undef, $type);
    [Lady_Aleena]: Or what Discipulus said.
    [shmem]: Lady_Aleena: geany supports ctags.
    [Discipulus]: a good compromise can be my ($need, $opts_ref) = @_ a scalar and an hash reference
    [Discipulus]: see you monks!
    [Lady_Aleena]: shmem, let me get this sub rewritten, then I will look into how to use ctags in geany. Deal? 8)
    [shmem]: Discipulus: yeah, that might eventually prepare the path for OO ;-)
    [Lady_Aleena]: See you, Discipulus.
    [shmem]: Lady_Aleena: that's up to you. I only wanted to show you a path that might be more comforting than command line grep ;-)
    [Lady_Aleena]: shmem, I don't think any of my modules could be converted to OO. They are too procedural.

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (8)
    As of 2017-04-27 12:25 GMT
    Find Nodes?
      Voting Booth?
      I'm a fool:

      Results (506 votes). Check out past polls.