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

Technically, if you only need to transform the date into a sortable key, you can just fudge the maths behind it to make it faster.

Say, the original date is MM-DD-YYYY (one of the most useless date formats available to modern computing), you could do something like this:

my $timestamp = '03-21-2021'; my ($month, $day, $year) = split/\-/, $timestamp; my $sortkey = $day + ($month * 100) + $year * 10000;

Now that the thing is an integer, you can compare numerically, which is faster than a string compare.

perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'