http://www.perlmonks.org?node_id=235355


in reply to Re: How do I print an array with commas separating each element?
in thread How do I print an array with commas separating each element?

Grr., I'd forgotten you can't reply to answers and have it be visible on the answer screen... Plus, this is only a mild (much shorter, tho) variation of another answer. *sigh* We're doing ridiculous ways now? Then why not do this?

my $x; my @a = qw(one two three); print $_, ++$x<@a ? ", " : "\n" foreach @a;

For bonus fun, you can crush all syntactical whitespace out of that print line, too.

Still, I'm thinking I'll stick with the built-in join() for future projects...

--
$you = new YOU;
honk() if $you->love(perl)

  • Comment on Re: Answer: How do I print an array with commas seperating each element?
  • Download Code