Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
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 having an uproarious good time at the Monastery: (3)
As of 2026-01-20 03:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (124 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.