in reply to Re: Pushing arrays around inside a loop ;-)
in thread Pushing arrays around inside a loop ;-)

Thanks guys. Actually I am getting the output that you got. Sorry I should have been more clear.

This is what I'm looking to get from the array:

v w x y z
w x y z v
x y z v w

And so on... If I'm shifting the contents of the array, shouldn't the value of the first position change, ie; $array[0]?

What I'm doing is working through 2 arrays, one not shown that simply repeats itself by resetting a counter. The other is the one I am having trouble with.

I'm trying to do this:

Employee1 v
Employee2 w
Employee3 x
Employee4 y
Employee5 z

Employee1 w
Employee2 x
Employee3 y
Employee4 z
Employee5 v

Employee1 x
Employee2 y
Employee3 z
Employee4 v
Employee5 w

And so on... It's a rotation schedule that I'm working on for my crew.

Replies are listed 'Best First'.
Re^3: Pushing arrays around inside a loop ;-)
by demerphq (Chancellor) on Jan 06, 2005 at 09:57 UTC

    Use modulo division and you dont have to modify the arrays at all.

    my @emps=map "employee_$_",1..5; my @codes='v'..'z'; my $n=3; for my $j (0..$n-1) { for my $i (0..$#emps) { print $emps[$i],":",$codes[($i+$j) % @codes],"\n"; } print "\n"; } __END__ employee_1:v employee_2:w employee_3:x employee_4:y employee_5:z employee_1:w employee_2:x employee_3:y employee_4:z employee_5:v employee_1:x employee_2:y employee_3:z employee_4:v employee_5:w
    ---
    demerphq

      Hey, demerphq, that worked like a charm! Thank you so much. I made a couple of hashes to substitute your output with employee names and work areas. I'll study this modulo division that you used. I've never worked with it before.

      Thanks again to everyone that helped me out. You all are very helpful when I come here from time to time with a problem.

      -Baratski