in reply to Get most recent data based on a date from an array of hashes.
sub mdy2ymd { my ($mdy) = @_; $mdy =~ /(..)-(..)-(....)/ and return "$3-$1-$2"; } my @filtered = sort { mdy2ymd($a->{Date}) cmp mdy2ymd($b->{Date}) } @$data;
For longer lists, you might want to use the Schwartzian transform so Perl doesn't have to convert each date several times.
Better yet, store the dates directly in the YYYY-MM-DD format and you can sort them the way you wanted.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Get most recent data based on a date from an array of hashes.
by Anonymous Monk on Jan 18, 2022 at 18:04 UTC | |
by Fletch (Bishop) on Jan 18, 2022 at 18:45 UTC | |
by Anonymous Monk on Jan 18, 2022 at 19:10 UTC | |
by Fletch (Bishop) on Jan 18, 2022 at 19:59 UTC | |
by Anonymous Monk on Jan 19, 2022 at 17:52 UTC | |
|