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

Re: Processing pairs of values from even-sized array

by AnomalousMonk (Archbishop)
on Jun 03, 2011 at 12:30 UTC ( [id://907962]=note: print w/replies, xml ) Need Help??


in reply to Processing pairs of values from even-sized array

Why not just:

while(@arr) { my ($x,$y) = (shift(@arr), shift(@arr)); ... }

Update: ... looks [like] the each generator ...
Maybe (see List::MoreUtils):

use List::MoreUtils qw(natatime); ;; my $it = natatime 2, @arr; while (my ($x, $y) = $it->()) { ... }

Replies are listed 'Best First'.
Re^2: Processing pairs of values from even-sized array
by rovf (Priest) on Jun 03, 2011 at 13:47 UTC
    Thanks a lot to you - and all the other ones who replied to my post! I was so focused on the idea having the declaration of my $x and $y inside the loop clause, that I didn't see this obvious solution!

    -- 
    Ronald Fischer <ynnor@mm.st>

Log In?
Username:
Password:

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

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

    No recent polls found