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!

How to tell the last iteration in a foreach loop? 1

Status
Not open for further replies.

meili100

Programmer
Aug 13, 2008
1
US
foreach $key (keys (%hash)){
print "$hash{$key}:";
}

The last element will also be followed by a ":" which is not what I want. Is there a way to tell when foreach loops to its last round, so that I can skip printing the last ":"? Thanks!
 
Code:
print join(':', map{$hash{$_}} keys %hash);

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top