in reply to POSIX strftime format question

Heres a nifty sub:
sub suffer { local $_ = shift; my$suf = 'th'; if( !/1.$/ ) { $suf = 'st' if /1$/; $suf = 'nd' if /2$/; $suf = 'r +d' if /3$/ } return $_.$suf; }
(Mostly stolen from peterS in #perl at freenode.net)

Replies are listed 'Best First'.
Re^2: POSIX strftime format question
by bart (Canon) on Oct 22, 2004 at 10:53 UTC
    Neat. That sounds like something I'd like to play with... Perl Golf, anyone?
    sub suffer { local $_ = shift; return $_ . (/(?<!1)([123])$/ ? (qw(- st nd rd))[$1] : 'th'); }
    Hmm, that's not very compact. But at least, it works. :)
Re^2: POSIX strftime format question
by Anonymous Monk on Oct 22, 2004 at 16:49 UTC
    sub suffer { $_[0].substr("stndrdththththththththththththththththth". "stndrdththththththththththst",2*$_[0]-2,2)}