Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

what about using $" ?

by harleypig (Scribe)
on Jun 27, 2005 at 00:23 UTC ( #470111=note: print w/ replies, xml ) Need Help??


in reply to Format a list with commas and "and"

What about this?

sub andify { return '' unless @_; return $_[0] if @_ == 1; local $" = @_ == 2 ? ' ' : ', '; $_[-1] = 'and ' . $_[-1]; return "@_"; }
Fixed squiggly brackets and should be $" not $,.
Fixed comma placement.
Got rid of blackberry comment.
Handled null case.
Changed regex to concatenation
Harley J Pig

20050525 Edit by ysth: p, code tags


Comment on what about using $" ?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2015-07-07 06:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (87 votes), past polls