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

Re: Pulling out oldest entries from a text file

by duff (Parson)
on Sep 04, 2007 at 14:35 UTC ( #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? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2021-10-24 00:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (88 votes). Check out past polls.

    Notices?