Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Like ambrus's solution, Time::Piece doesn't recognize fractions of a second, (I believe), and I had to edit them out before feeding to the the strptime method for Time::Piece.

I noticed that the beginning times for each like Team-City pairing was the same. I didn't know if this was coincidence or that they would be the same in every case. This solution doesn't assume that.

#!/usr/bin/perl use strict; use warnings; use Time::Piece; # core since Perl v5.9.5 my @data; open my $fh, "<", 'o33.txt' or die $!; while (<$fh>) { push @data, [ split /,/ ]; my ($start, $end) = map Time::Piece->strptime($_, "%Y-%m-%d %H:%M: +%S"), map s/\.\d\d\d$//r, @{ $data[-1] }[2,3]; push @{ $data[-1] }, $end - $start; # piggyback elapsed seconds $d +ata[r][c] } close $fh or die $!; my %seen; my @lines = grep {!$seen{ "@$_[1,4]" }++} sort {$a->[1] cmp $b->[1] || $b->[-1] <=> $a->[-1]} @data; for my $rec (@lines) { printf "%s,%s,%0.2f hours\n", @$rec[1,4], $rec->[-1]/3600; } __END__ *** input (o33.txt) 1,BEAR,2011-11-21 08:49:16.000,2011-11-21 08:53:13.910,San Francisco,, +, 2,BEAR,2011-11-21 08:49:16.000,2011-11-21 12:50:31.550,San Francisco,, +, 3,BEAR,2011-11-21 08:49:16.000,2011-11-21 08:49:19.987,San Francisco,, +, 4,HAWK,2011-11-21 10:36:26.000,2011-11-21 10:45:11.823,Los Angeles,,, 5,HAWK,2011-11-21 10:36:26.000,2011-11-21 12:41:17.763,Los Angeles,,, 6,HAWK,2011-11-21 10:41:12.000,2011-11-21 10:55:08.393,San Francisco,, +, 7,HAWK,2011-11-21 10:41:12.000,2011-11-21 15:46:24.707,San Francisco,, +, 8,HAWK,2011-11-21 10:41:12.000,2011-11-22 11:09:13.907,San Francisco,, +, *** output BEAR,San Francisco,4.02 hours HAWK,San Francisco,24.47 hours HAWK,Los Angeles,2.08 hours

In reply to Re: Need help get longest timediff by Cristoforo
in thread Need help get longest timediff by britney

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 making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-19 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found