in reply to Traversing succeding sets of an array

Maybe splice is your friend:

my $elementsToGet = 2; # how many elements shell be in @sublist my @newElements = @elements; while (my @subList = splice(@newElements, 0, $elementsToGet)) { # do something with @subList } # while Beware that @newElements might be empty after the while...
or, with a counter:
for (my $i=0; $i<=$#elements; $i+=2) { # do something with $elements[$i] and $elements[$i+1] } # for
I haven't tested these codes.

Best regards,
perl -le "s==*F=e=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print"

Replies are listed 'Best First'.
Re: Re: Traversing succeding sets of an array
by very empty (Scribe) on May 14, 2002 at 16:13 UTC
    I do not have a even-sized list and I need to have to do also to do something with  ($elements[$i=2*$j-1],$elements[$i+1])