Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
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 ( [id://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?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-24 02:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found