Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Pulling out oldest entries from a text file

by Anno (Deacon)
on Sep 04, 2007 at 14:43 UTC ( [id://636954]=note: print w/replies, xml ) Need Help??


in reply to Pulling out oldest entries from a text file

You don't need a date function to determine the oldest date. Your dates are formatted so that string comparison works. Here is a way to extract the oldest entry for each group:
use List::Util qw( maxstr); my %tb; while ( <DATA> ) { my ( undef, $group, $entry_date) = split; $tb{ $group}->{ $entry_date} = $_; } print $_->{ maxstr keys %$_} for values %tb; __DATA__ 34 gr1 2003-03-02 12 gr1 1990-03-14 39 gr3 2002-04-11 66 gr4 2006-03-16 32 gr3 1998-02-13 90 gr1 2004-06-15 55 gr4 1999-06-15
Update: Code cleaned up

Anno

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-03-28 15:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found