Given a list of dates, to calculate a corresponding list of ordinals I might do something like the following:
# Make a list of tuples: (index, date)
my @list = map { [ $_, $dates[$_] ] } (0..$#dates);
# Sort the list by date
@list = sort { Date_Cmp($a->[1], $b->[1]) } @list;
# Determine the corresponding ordinal numbers
my @ordinals;
foreach (0..$#dates) {
$ordinals[ $list[$_]->[0] ] = $_ + 1;
}
I don't find this very elegant - there may be much better ways. There may be a module that does this, though I don't know one.