in reply to Format a list with commas and "and"
I was always taught that the correct way of printing lists like that was "A, B, C and D" (i.e. no comma before the "and"). If your English teacher was like mine then this version will work better for you:
--sub and_a_list { if (@_ > 2) { join(", ", @_[0..$#_-1]) . " and $_[-1]" } elsif (@_ > 1) { "$_[0] and $_[1]" } elsif (@_ > 0) { $_[0] } else { "" } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: Format a list with commas and
by tye (Sage) on Aug 24, 2000 at 19:03 UTC | |
by providencia (Pilgrim) on Aug 30, 2000 at 18:40 UTC | |
|
Re: Format a list with commas and
by Abigail-II (Bishop) on Oct 02, 2002 at 10:46 UTC | |
by Aristotle (Chancellor) on Oct 04, 2002 at 20:40 UTC |