Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: English Date-Suffixes

by cLive ;-) (Prior)
on Nov 04, 2002 at 07:54 UTC ( [id://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 ;-)

Replies are listed 'Best First'.
Re: Re: English Date-Suffixes
by BrowserUk (Patriarch) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://210138]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2024-04-20 05:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found