in reply to Processing Multiple Array Elements
Perhaps I don't understand what that nested while loop is demonstrating in your sample code....#!/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
-Blake
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Processing Multiple Array Elements
by shotgunefx (Parson) on Sep 11, 2001 at 14:54 UTC |