Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Pulling out oldest entries from a text file

by duff (Parson)
on Sep 04, 2007 at 14:35 UTC ( [id://636950]=note: print w/replies, xml ) Need Help??


in reply to Pulling out oldest entries from a text file

Since your dates appear to be in a nice comparable format, you can just do ordinary string comparisons on them to find out which is oldest. So ... something like this should work fine:

#!/usr/bin/perl use strict; use warnings; my (%oldest_date, %oldest_entry); while (<DATA>) { my ($item,$group,$date) = split; if (!exists $oldest_date{$group} || $date lt $oldest_date{$group}) + { $oldest_date{$group} = $date; $oldest_entry{$group} = $_; } } for my $g (keys %oldest_entry) { print $oldest_entry{$g}; } __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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://636950]
help
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 04:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found