sub serial {
join(', ', @_[0..$#_-1]) .
(@_>2 ? ',':'' ) .
(@_>1 ? (' and ' . $_[-1]) : $_[-1]);
}
####
my @primate = qw( sifaka gibbon tarsier langur );
print "Endangered primates: ", serial(@primate), ".\n";
####
# in some parent formatting, template processing module
use Template; # not actually using it in the code here
use Template::Stash;
$Template::Stash::LIST_OPS->{ serial } =
sub {
my @list = @{ +shift || [] };
join(', ', @list[0..$#list-1]) .
(@list>2 ? ',':'' ) .
(@list>1 ? (' and ' . $list[-1]) : $list[-1]);
};
####
Hey, Joe. Where you going with that
[% user.ListOfItems.serial %] in your hand?