Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Answer: How do I loop through a list two or more elements at a time?

by Sidhekin (Priest)
on Oct 24, 2001 at 15:34 UTC ( #121079=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    for (map{{el1=>$list[2*$_], el2=>$list[2*$_+1]}} 0 .. $#list/2) {
        # do things with $_->{el1} and $_->{el2}
    }
    
  2. or download this
    for (my $i=0 ; $i < @list ; $i+=2) {
        my ($el1, $el2) = @list[$i,$i+1];
        # do things with $el1 and $el2
    }
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2022-05-23 21:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (82 votes). Check out past polls.

    Notices?