regex - How do I retrieve an integer's ordinal suffix in Perl (like st, nd, rd, th) -


i have number , need add suffix: 'st', 'nd', 'rd', 'th'. example: if number 42 suffix 'nd' , 521 'st' , 113 'th' , on. need in perl. pointers.

try this:

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

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

c++ - Accessing inactive union member and undefined behavior? -

php - Get uncommon values from two or more arrays -