in reply to Comparing rows keeping latest
-imranmy %latest; foreach my $line (@data_241) { # split line my ($id, $date) = split(/\s+/, $line); if (! exists($latest{$id}) { # place in hash if not seen before $latest{$id} = $date; } else { # place in hash if date is greater than the one in hash $latest{$id} = $date if substr($date,4,4).substr($date,0,4) ge substr($latest{$id},4,4).substr($latest{$id},0,4); } } foreach my $key (sort keys %latest) { # print out the latest values print NEW "$key\t$latest{$key}\n"; }
|
|---|