I have an array like:
@array = ("12 hours", "23 minutes", "17 seconds");
I am trying to turn this into an English sentence like "12 hours,
23 minutes, and 17 seconds" Not so tough right? The real problem is that I never know how many
items are in the list. The best that I could come up with was:
$last = pop(@array);
$sentence = join ", ", @array;
$sentence .= "," if ($#array > 0);
$sentence .= " and " if ($#array > -1);
$sentence .= "$last";
This works for anything, except zero elements, which I check for earlier in the block.
I'm sure some of you wizards can see what I cannot. Any help is appreciated.
=IndyZ