Subject: | WORDLIST omits content when scalar @list > 3 |
The following script:
#!/usr/bin/perl
use Lingua::EN::Inflect qw /WORDLIST/;
my @list = ("a", "b", "c", "d", "e");
print WORDLIST(@list);
will print:
a, d, and e
b and c are missing. Actually only items number 1, -2 and -1 are
returned. All the other items are always omitted. This is because the
return statement of sub WORDLIST is incorrect:
return join($sep, @words[0,@words-2]) . "$final_sep$words[-1]";
should be:
return join($sep, @words[0..@words-2]) . "$final_sep$words[-1]";
(Note the ".." instead of ",")
I propose to add the following tests to wordlist.t, so that lists > 3
are tested:
# Four words...
@words = qw(apple banana carrot tomato);
is WORDLIST(@words),
"apple, banana, carrot, and tomato"
=> 'plain 4 words';
is WORDLIST(@words, {final_sep=>''}),
"apple, banana, carrot and tomato"
=> '4 words, no final sep';
is WORDLIST(@words, {final_sep=>'...'}),
"apple, banana, carrot... and tomato"
=> '4 words, different final sep';
is WORDLIST(@words, {final_sep=>'...', conj=>''}),
"apple, banana, carrot... tomato"
=> '4 words, different final sep, no conjunction';
is WORDLIST(@words, {conj=>'or'}),
"apple, banana, carrot, or tomato"
=> '4 words, different conjunction';
I tested it and it works fine.