in reply to Format a list with commas and "and"
The everything is the same except the last element problem seems to come up quite a bit; my approach is generally to do the same thing to them all and then "fixup" the last one. summersub and_a_list { my $r = join(', ', @_); my $pos = rindex($r, ', '); substr($r, $pos, 2) = ' and ' if $pos > -1; $r; }
|
|---|