in reply to Format a list with commas and "and"
What about this?
Fixed squiggly brackets and should be $" not $,.sub andify { return '' unless @_; return $_[0] if @_ == 1; local $" = @_ == 2 ? ' ' : ', '; $_[-1] = 'and ' . $_[-1]; return "@_"; }
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
|
---|
In Section
Cool Uses for Perl