Easy way to print Perl array? (with a little formatting)

funk-shun picture funk-shun · Apr 21, 2011 · Viewed 253.4k times · Source

Is there an easy way to print out a Perl array with commas in between each element?

Writing a for loop to do it is pretty easy but not quite elegant....if that makes sense.

Answer

Alex picture Alex · Apr 21, 2011

Just use join():

# assuming @array is your array:
print join(", ", @array);