Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Test for the last element in a foreach

by mvc (Scribe)
on Aug 03, 2007 at 13:29 UTC ( [id://630508]=note: print w/replies, xml ) Need Help??


in reply to Test for the last element in a foreach

No need for a test on each iteration:
my @children = $category->children; my $last_child = pop @children; foreach $child (@children) { handle_not_last_child($child); } handle_last_child($last_child);

Replies are listed 'Best First'.
Re^2: Test for the last element in a foreach
by smithers (Friar) on Aug 03, 2007 at 19:02 UTC
    Nice mvc++, I like your solution.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://630508]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2025-02-14 20:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found