Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: 'prev' in for loop

by gjb (Vicar)
on Dec 06, 2005 at 14:28 UTC ( [id://514467]=note: print w/replies, xml ) Need Help??


in reply to 'prev' in for loop

prev simply isn't Perl. next and last are though.

You can always rewrite a for-loop from:

foreach my $item (@list) { something($item); }
to
for (my $i = 0; $i < @list; $i++) { something($list[$i]); }
By modifying $i you can get to the "previous" iteration (something like $i--. However, be careful not to create an infinite loop.

Hope this helps, -gjb-

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-18 21:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found