Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Time Intervals

by johngg (Abbot)
on Jun 27, 2012 at 22:13 UTC ( #978781=note: print w/ replies, xml ) Need Help??


in reply to Time Intervals

Construct a hash of arrays keyed by value in the file, containing arrays of lines for each value in case there is more than one time period with the same value. Use List::Util->max to find the largest key in the hash and print the line(s) associated with it.

knoppix@Microknoppix:~$ perl -Mstrict -Mwarnings -MList::Util=max -E ' > open my $fh, q{<}, \ <<EOD or die $!; > 10:38:34 759 > 10:43:34 735 > 10:48:34 817 > 10:53:34 648 > 10:58:34 817 > 11:03.34 774 > EOD > > my %byValue; > while ( <$fh> ) > { > my $value = ( split )[ 1 ]; > push @{ $byValue{ $value } }, $_; > } > > print for @{ $byValue{ max keys %byValue } };' 10:48:34 817 10:58:34 817 knoppix@Microknoppix:~$

I hope this is helpful.

Cheers,

JohnGG


Comment on Re: Time Intervals
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://978781]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2014-12-25 18:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (161 votes), past polls