Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing a list with commas (Array) 1

Status
Not open for further replies.

Extension

Programmer
Nov 3, 2004
311
CA
Hi,

I'm trying to figure out a simple way to print a list seperated by commas (from an array), but I don't want a comma after the last value.

Code:
@array = ('one','two','three','four','five');

	foreach my $word (@array) {
		print "$word " . ",";
	}

one, two, three, four, five,

to

one, two, three, four, five

Thanks in advance
 
Try
Code:
my @array = qw ( one two three four five );
print (join ', ', @array), "\n";

Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top