in reply to Re: Implementing a cyclic array
in thread Implementing a cyclic array

the code i've written to map the elements is as follows :
foreach (@array_1) { print "$array_2[0] maps to $_\n"; push(@array_2, shift @array_2); }

Replies are listed 'Best First'.
Re^3: Implementing a cyclic array
by ramlight (Friar) on Jun 19, 2009 at 13:28 UTC
    While many of the other solutions are perhaps a closer fit to your problem, I thought that I would show you a solution that is closer to the code that you tried:
    use strict; use warnings; my @array_1 = ("tom","harry","diana","nick","sally","henry"); my @array_2 = ("play()","eat()","sleep()"); foreach (@array_1) { my $action = shift(@array_2); print "$action maps to $_\n"; push(@array_2, $action); } which prints play() maps to tom eat() maps to harry sleep() maps to diana play() maps to nick eat() maps to sally sleep() maps to henry