Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: 'prev' in for loop

by rinceWind (Monsignor)
on Dec 06, 2005 at 15:45 UTC ( [id://514507]=note: print w/replies, xml ) Need Help??


in reply to 'prev' in for loop

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.

--

Oh Lord, won’t you burn me a Knoppix CD ?
My friends all rate Windows, I must disagree.
Your powers of persuasion will set them all free,
So oh Lord, won’t you burn me a Knoppix CD ?
(Missquoting Janis Joplin)

Replies are listed 'Best First'.
Re^2: 'prev' in for loop
by swampyankee (Parson) on Dec 06, 2005 at 16:16 UTC

    Of course, Acme::ChronoNaught is the only complex module which was released with absolutely no bugs, as the developers were able to process all bug reports before releasing the module.

    Plus, they can devote all their time to Perl advocacy, since their tests were useful for investment planning.

    emc

    Netlib

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-23 10:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found