in reply to Sentances from arrays

Here's what I use:
sub list_commify { if (@_ > 2) { join ", ", @_[0..$#_-1], " and $_[-1]" } elsif (@_ > 1) { "$_[0] and $_[1]" } elsif (@_ > 0) { $_[0] } else { "" } }

Replies are listed 'Best First'.
Re: Re: Sentances from arrays
by IndyZ (Friar) on Nov 28, 2000 at 04:56 UTC
    Personally, I don't like if's. In my mind, they make code harder to read by forcing you to think your way through them. While they are appropriate in other cases, in this case I believe merlyn is clearer.

    =IndyZ

      To each his own, natch. For me, at least, it's easier to parse the if's, since it's more English-like. I can parse it by reading it aloud.

      I find it harder to pronounce the ? : version, though I appreciate its elegance.