in reply to Comparing rows keeping latest
One trick is to normalize the date so you can compare it directly:
use warnings; use strict; my %bestLine; while (<DATA>) { my ($line, $month, $day, $year) = /(\d+)\s+(\d{2})(\d{2})(\d{4})/; my $date = "$year$month$day"; $bestLine{$line} = $date if ! exists $bestLine{$line} or $bestLine{$ +line} < $date; } print join "\n", map {"$_: $bestLine{$_}"} sort keys %bestLine; __DATA__ 13 10102005 13 09152005 13 11052005 200 11012005 200 11152004
Prints:
13: 20051105 200: 20051101
Update: revise code to match OP's problem.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Comparing rows keeping latest
by Anonymous Monk on Feb 20, 2006 at 20:27 UTC |