Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Get most recent data based on a date from an array of hashes.

by haukex (Bishop)
on Jan 18, 2022 at 17:46 UTC ( #11140573=note: print w/replies, xml ) Need Help??


in reply to Get most recent data based on a date from an array of hashes.

One way might be to parse the dates via Time::Piece into a new value into the hashes and then sorting based on that, e.g.

$_->{TimePiece} = Time::Piece->strptime($_->{Date}, '%m-%d-%Y') for @$ +data; my @filtered = sort { $a->{TimePiece} <=> $b->{TimePiece} } @$data;

Fetching the most recent result out of the array and removing the TimePiece key back out of the hash left as an exercise to the reader.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11140573]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2022-05-29 12:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (101 votes). Check out past polls.

    Notices?