Search code examples
perltext-formatting

How can I output a list as comma-separated values in Perl?


Let's say I have a list of elements

@list=(1,2,3);
#desired output
1,2,3

and I want to print them as comma separated values. Most importantly, I do not want the last element to have a comma after it.

What is the cleanest way to do this in Perl?


Solution

  • print join(',', @list), "\n";