in reply to Implementing a cyclic array

Show what you tried (perl code).

Replies are listed 'Best First'.
Re^2: Implementing a cyclic array
by perlpal (Scribe) on Jun 19, 2009 at 11:58 UTC
    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); }
      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