perl - How to go through odd index of an array using foreach loop? -
i want access $array[$i] , $array[$i+1] in every iteration of foreach loop , think need this
$index = 0; foreach $element (@array) { // access $element // access $array[$index+1] $index++; } but if in way , i+1 iteration go through again, if want let loop go through , i+2 , i+4 , i+6 ... how can do?
thanks
for(my $i=0; $i<scalar(@array)-1; $i+=2) { $ele1 = $array[$i]; $ele2 = $array[$i+1];
Comments
Post a Comment