in reply to Processing Multiple Array Elements

I'm not entirely sure if this is what you are trying to do... However, if all you need to do is loop through an array processing $N elements at a time, wouldn't it be easier to just take some slices with calculated indices?
#!/usr/bin/perl -wT use strict; my @a = (1..16); # test array my $atatime = 3; # number of elements to loop over for my $i (0..$#a/$atatime) { # loop through @a/$atatime times my $min = $i*$atatime; # index of low element my $max = $min+$atatime-1; # index of high element $max = $#a if $max > $#a; # make sure we don't fall off the end print join(", ", @a[$min..$max]),"\n"; # do something with our slic +e } # Verify that we haven't munged our values print "\nStill There: ", join(' ',@a), "\n"; =output 1, 2, 3 4, 5, 6 7, 8, 9 10, 11, 12 13, 14, 15 16 Still There: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Perhaps I don't understand what that nested while loop is demonstrating in your sample code....

-Blake

Replies are listed 'Best First'.
Re: Re: Processing Multiple Array Elements
by shotgunefx (Parson) on Sep 11, 2001 at 14:54 UTC
    Yeah, it would have been much easier, but I just got it in my head that I should be able to do it THAT way and that it must be possible, so there it is. Now instead the of login code that I should have finished, I have this construct of dubious value.

    The loop was just to show that the nested calls work and if for some reason you thought it was a good thing, that the remainder of the list was visible to any enclosing statements.

    Like I said, I'll probably only using it for spitting out tables.

    update
    A lil example.
    my @dictionary =(lots o words); print start_table(); while(@words = elements(@dictionary, $columns)){ print Tr(td([@words])); } print end_table();
    -Lee

    "To be civilized is to deny one's nature."