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
    Thanks, I was thinking of using slices etc. but using % is an excellent solution - I would have never thought of it.

    Cheers Very much - ya deserve a pat on back.
    Regards
    Mark K