Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: 'prev' in for loopby rinceWind (Monsignor) |
on Dec 06, 2005 at 15:45 UTC ( [id://514507]=note: print w/replies, xml ) | Need Help?? |
To get the perl verb 'prev', you need to install Acme::ChronoNaught, which has useful applications for horse racing and the stock market ;). Seriously though, I think you have misunderstood the operation of the verbs 'last' and 'next'. The three verbs 'last', 'next' and 'redo' are control verbs - glorified goto. They cause execution to jump: out of the loop, into the next iteration, and to the start of the current iteration, respectively. If you want the previous value of your index, you need to store it somewhere - in $prev declared outside the scope of the loop. Set this at the end of your loop, and next time round it will hold what you want.
Of course, if you are counting, you can always subtract 1. --
In Section
Seekers of Perl Wisdom
|
|