in reply to Re^4: Golf - Ordinal Suffixes
in thread Golf - Ordinal Suffixes

One bareword hardly seems enough:

sub num2ord { local $_ = shift; # 1 2 3 4 # 123456789012346789012345678901234567890 $_.((0,st,nd,rd)[/1?.$/g]||th) }

Update: oops, typo: too many parens at start.

Hugo

Replies are listed 'Best First'.
Re^6: Golf - Ordinal Suffixes
by truedfx (Monk) on Nov 03, 2005 at 12:43 UTC
    sub num2ord { local $_ = shift; # 1 2 3 4 # 1234567890123**789012345678901234567890 $_.((0,st,nd,rd)[/1?.$/g]||th) }
    Those ** should be 456, not 46 - that appears to have been copied by everyone ;)

    Also, one extra character can be removed:
    sub num2ord { local $_ = shift; # 1 2 3 # 123456789012345678901234567890 $_.=(0,st,nd,rd)[/1?.$/g]||th }