A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

Determine a day's ordinal suffix: 1st, 2nd, 3rd, 4th, etc.

e.g. for dates you don't want to display "19 July" but rather "19th July":

my $ordinal;
if ($foo =~ /(?<!1)1$/) {
    $ordinal = 'st';
} elsif ($foo =~ /(?<!1)2$/) {
    $ordinal = 'nd';
} elsif ($foo =~ /(?<!1)3$/) {
    $ordinal = 'rd';
} else {
    $ordinal = 'th';
}

Bonus points if you can integrate this with DateTime's strftime() method neatly.

(source)