PERL:


PERL: - . 119


sub commify_series { (@_ == 0) > ' '

(@_ ==1)9 $_[0]

(@_ == 2) ? ]oin(" and ', @_)

(", ', @_[0 ($#_-1], 'and $_[-1]"),

:

@array = ('red", "yellow", 'green'),


118 4

print "I have ", @array, " marbles \n'; print "I have @array marbles\n", I have redyellowgreen marbles. I have red yellow green marbles.

"I have red, yellow, and green marbles". ­ . ­ "and". , .

4.1 : , ­ .

4.1. commify_series

#'/usr/bin/perl -w

# commify_senes -

lists = (

[ 'just one thing' ], [ qw(Mutt Jeff) ], [ qw(Peter Paul Mary) ],

[ 'To our parents', 'Mother Theresa', 'God' ],

[ 'pastrami', 'ham and cheese', 'peanut butter and jelly', 'tuna' ], [ 'recycle tired, old phrases', 'ponder big, happy thoughts' ], [ 'recycle tired, old phrases', 'ponder big, happy thoughts', 'sleep and dream peacefully ],

foreach $aref (@lists) {

print "The list is ' . commify_series((g>$aref) . \n",

sub commify_series {

my $sepchar = grep(/,/ => @_) 9 "; ' ",",

(@_ == 0) ? ' :

(@_ == 1) ? $_[0] :

(@_ == 2) ? join(" and ', @_)

join("$sepchar ', @_[0 ($#_-1)], "and $_[-1]"); }

:

The list is: just one thing.

The list is: Mutt and Jeff.




- -  - -  - -