My version. What can I say, I like the ? : operator :)
Usage: &print_with_ands(\@array);
sub print_with_ands { my $x=0; my $a=shift; printf "$a->[$x-1]%s", defined $a->[$x+1] ? ", " : ! defined $a->[$x] ? "\n" : $x==1 ? " and " : ", and " while defined $a->[$x++]; }
In reply to RE: Format a list with commas and 'and'
by turnstep
in thread Format a list with commas and "and"
by merlyn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |