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

Re^2: Increment by 2 and by 1 in same loop.

by AnomalousMonk (Canon)
on Apr 16, 2013 at 10:21 UTC ( #1028869=note: print w/replies, xml ) Need Help??

in reply to Re: Increment by 2 and by 1 in same loop.
in thread Increment by 2 and by 1 in same loop.

It's also possible to define (and initialize, if needed) two (or more) lexical loop variables entirely locally:

for (my ($i, $n) = (1, 2); $i < $limit; $i += 2, ++$n) { do_something_with($i, $n); }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1028869]
[Eily]: I just wrote a oneliner to solve a (non perl) colleague's problem, and it worked on the first try
[Eily]: and he wasn't impressed
1nickt adds gingersnaps to the platter on the sideboard.
[Eily]: sure it was a pretty standard one liner (of the $h{$1} = $2 if /regex/; END { pp \%h; } variety), but he's not supposed to know that!
[Eily]: what's the point of writing perl if people aren't impressed :P
[sierpinski]: Haha
[Discipulus]: i'm with you!
[Discipulus]: with eskimo greeting is a little bit impressing, anyway

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2017-04-26 15:06 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (482 votes). Check out past polls.