Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Answer: How do I print an array with commas separating each element?

by turnstep (Parson)
on Aug 30, 2000 at 18:33 UTC ( #30292=categorized answer: print w/replies, xml ) Need Help??

Q&A > arrays > How do I print an array with commas separating each element? - Answer contributed by turnstep

Here's another way:

my $x = 0; printf "$array[$x-1]%s", $x <= $#array ? "," : "\n" while $array[$x++];

It puts a newline instead of a comma after the last element.

  • Comment on Answer: How do I print an array with commas separating each element?
  • Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2021-01-25 14:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?