Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

what about using $" ?

by harleypig (Monk)
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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://470111]
[Discipulus]: I havery limited needs in such field. Sometimes (for children party invitations) i draw something by hand and I scan it to include into an ms doc.
Discipulus havery can be a good neologism for: have very..;=)
[ambrus]: Discipulus: sure, it's just that, look, some people (including me) have such unreadable and slow handwriting that writing an article or slides by hand would be a very bad idea.
[choroba]: it might bery useful for other verbs, too
[ambrus]: (and I have a need for at least decent formatting too)

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2017-09-26 11:30 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (293 votes). Check out past polls.