Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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 taking refuge in the Monastery: (4)
As of 2024-09-19 05:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (25 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.