in reply to looping backwards
The usual way to do a circular array is to use the % operator. For example, this will start from Joe (offset 2):
my @array=qw/ Fred Mark Joe Mary Paul /; my $offset=2; for (0..$#array) { print $array[$offset++ % @array], "\n" }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: looping backwards
by Anonymous Monk on Jul 29, 2003 at 10:05 UTC |