in reply to adding st,nd,rd and th to numbers

Is there any reason why you couldn't just use this?
my $num = $ARGV[0]; $num .= 'st' if (substr($num, -1) == 1); $num .= 'nd' if (substr($num, -1) == 2); $num .= 'rd' if (substr($num, -1) == 3); $num .= 'th' if (substr($num, -1) > 3); print "$num\n";

Replies are listed 'Best First'.
Re^2: adding st,nd,rd and th to numbers
by nothingmuch (Priest) on Jul 19, 2005 at 19:29 UTC
    Well, the 11st and 12nd reasons for one.

    Update: the 10 reason is also malfunctioning.

    -nuffin
    zz zZ Z Z #!perl
      Sorry, those few odd numbers obviously passed over my mind. I retract my answer.
Re^2: adding st,nd,rd and th to numbers
by zshzn (Hermit) on Jul 19, 2005 at 19:33 UTC
    If I can slightly add to that, it needs a similar case for 0.

    It doesn't structure as if, elsif, else, because should it work on any case the addition will guarantee that it will not pass on any of the following.