http://qs1969.pair.com?node_id=11140571

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

Trying to get the most recent data set from this array, "sort" not working, prints all the data instead.
I only want to get the most recent:

{ 'Color' => 'green', 'Step' => 'Platform', 'acc' => '1111', 'Date' => '08-06-2022' }
Which is the most recent based on the " 'Date' => '08-06-2022'".
Any suggestions?

Test code:
#!/usr/bin/perl -w use strict; use Data::Dumper; my $data = [ { 'Color' => 'green', 'Step' => 'Platform', 'acc' => '1111', 'Date' => '08-06-2022' }, { 'Color' => 'black', 'Step' => 'Platform', 'acc' => '1111', 'Date' => '01-05-2019' }, { 'Color' => 'blue', 'Step' => 'Platform', 'acc' => '1111', 'Date' => '10-11-2020' }, { 'Color' => 'white', 'Step' => 'Platform', 'acc' => '1111', 'Date' => '01-03-2022' }, { 'Color' => 'red', 'Step' => 'Platform', 'acc' => '1111', 'Date' => '03-21-2021' }, ]; my @filtered = sort { $a->{Date} cmp $b->{Date} } @$data; print Dumper @filtered;

Thanks for looking!