Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
more useful options
 
PerlMonks  

Re: English Date-Suffixes

by cLive ;-) (Parson)
on Nov 04, 2002 at 07:54 UTC ( #210138=note: print w/ replies, xml ) Need Help??


in reply to English Date-Suffixes

You can get it down another 6 chars to 41 by a little rewriting, and the $ in the regex and final semi-colon aren't needed:

shift;/1\d/?0:qw(0 st nd rd)[$_%10]or'th'

.02

cLive ;-)


Comment on Re: English Date-Suffixes
Download Code
Re: Re: English Date-Suffixes
by BrowserUk (Pope) on Nov 04, 2002 at 19:52 UTC

    If you can live with the risk of the sub stomping on the callers copy of $_ by not localising it, then you could trim a couple more keystrokes by using pop instead of shift, and you also can trim the regex by another 1

    pop;/1./?0:qw(0 st nd rd)[$_%10]or'th'

    Nah! Your thinking of Simon Templar, originally played by Roger Moore and later by Ian Ogilvy
Re: Re: English Date-Suffixes
by petral (Curate) on Nov 05, 2002 at 00:45 UTC
    Is this what you want? (Neither pop nor shift load $_ by defalult -- they just default to using @_ in a sub or @ARGV in the main prog.)
    $_=pop;qw(0 st nd rd)[!/1./&&$_%10]or'th'


      p

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://210138]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (15)
As of 2013-05-20 14:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (414 votes), past polls