Ah, ok, that's clear now.
You want the entries for latest date in each group id. Your date format is fortunate because it can be ordered alphabetically.
That gives the @res you wanted. The sort call only puts the elements in group order. If you don't care about that you can replace the line with just values %group;use Data::Dumper; my @array = ( ['ashok',15,'2006-01-01'], ['ashokpj',15,'2006-02-01'], ['ravi',56,'2006-03-01'], ['raja',56,'2006-02-01'], ); my @res = do { my %group; for (@array) { # $group{$_->[1]} = $_ if $_->[2] gt $group{$_->[1]}; bad $group{$_->[1]} = $_ if $_->[2] gt $group{$_->[1]}[2]; } sort {$a->[1] <=> $b->[1]} values %group; }; print Dumper \@res; __END__ $VAR1 = [ [ 'ashokpj', 15, '2006-02-01' ], [ 'ravi', 56, '2006-03-01' ] ];
Edit: Oops! I left an index off my comparison - corrected. Thanks, anon. Added dump.
After Compline,
Zaxo
In reply to Re^3: How to filter the array with id of max. date.
by Zaxo
in thread How to filter the array with id of max. date.
by ashokpj
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |