Text::Conjunct - join lists of items together
print conjunct "and", "3 apples", "2 pears", "no oranges";
3 apples, 2 pears, and no oranges
Text::Conjunct joins strings together with a conjunction, typically "and" or "or".
If there is only one string, it is just returned.
If there are two strings, they are returned with the supplied conjunction between them.
If there are three or more strings, all but the last are separated by commas. The separator between the second-to-last and the last is the conjunction, possibly with a comma preceding it (see "SERIAL COMMAS" below).
$string = conjunct $conjunction, @list;
Returns the strings conjoined as explained above. $conjunction can be any string, which can yield nonsensical results; generally it will be "and" or "or".
conjunct "and", "one apple"
conjunct "and", "one apple", "two oranges"
one apple and two oranges
conjunct "and", "one apple", "two oranges", "three pears"
one apple, two oranges, and three pears
Text::Conjunct defaults to placing a comma before the final conjunction if there are more than two connected phrases (William Strunk Jr. and E.B. White, The Elements of Style, rule 2). This is commonly called the serial comma. Many people, however, omit this comma. I am not one of them, because this seems illogical to me, and frequently results in unintended ambiguity. Compare
I'd like to thank my parents, Ayn Rand and God.
I'd like to thank my parents, Ayn Rand, and God.
and see which you think makes more sense. Commas in writing generally reflect pauses in speech, and pretty much everybody except the children of Ayn Rand and God will pause between those two terms.
But this is Perl, where the standard dogma is that we don't do dogma. You can set the global variable
$Text::Conjunct::SERIAL_COMMA to reflect your preference or requirements. It defaults to 1 to reflect my personal preference, but you can set it to zero if you would rather do it the other way.
Copyright 2004 Kevin Michael Vail
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Kevin Michael Vail <firstname.lastname@example.org>