in reply to Golf - Ordinal Suffixes
Update: and here's my 40-char entry:sub num2ord { my $n = shift; # 1 2 3 4 5 6 +7 # 12345678901234678901234567890123456789012345678901234567890123456789 +0 $n.($n=~/1.$/?'th':qw(th st nd rd)[$n=~/([123]?)$/]) }
It's not strict-safe, and will throw a warning if warnings are turned on. And I can trim one more character off, but I'll leave that up to you to find!sub num2ord { my $n = shift; # 1 2 3 4 5 6 +7 # 12345678901234678901234567890123456789012345678901234567890123456789 +0 $n.(qw(th st nd rd)[$n=~/(1?\d)$/]||th) }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Golf - Ordinal Suffixes
by sauoq (Abbot) on Oct 27, 2005 at 03:54 UTC | |
by japhy (Canon) on Oct 27, 2005 at 04:21 UTC | |
by sauoq (Abbot) on Oct 27, 2005 at 05:02 UTC | |
by hv (Prior) on Oct 27, 2005 at 09:18 UTC | |
by truedfx (Monk) on Nov 03, 2005 at 12:43 UTC |