Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Test for the last element in a foreach (list)

by tye (Sage)
on Aug 02, 2007 at 20:47 UTC ( [id://630393]=note: print w/replies, xml ) Need Help??


in reply to Test for the last element in a foreach

With your update, you could just assign the returned list to a named array. Or, for fun, do something crazy like:

sub children { return ( 1..5 ); } my( $end, $subcat ); foreach my $next ( children(), $end ) { if( ! $end ) { $end= 1; $subcat= $next; next; } if( \$next == \$end ) { print "Last element.\n"; } print $subcat, $/; $subcat= $next; } __END__ 1 2 3 4 Last element. 5

- tye        

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2025-03-17 04:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When you first encountered Perl, which feature amazed you the most?










    Results (54 votes). Check out past polls.