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
|
|---|