Hi everyone,
I am working on some perl stuff at the moment and it been a while so maybe i am being really stupid here, but...
I want to shuffle an array. i.e. take one item off the top and but it back on the bottom.
I thought that the difference between shift and pop was which end of the array they get the element from (and of course the same with unshift and push).
So my code is as follows....
sub randomSector{
@array = @_;
$arrayElementToMove = shift(@array);
push(@array, $arrayElementToMove);
my $retString = join(', ', @array);
return $retString;
}
But this seems to put it right back where i got it from.. not on the other end of the array.
Any help greatly appreciated!
Thanks
Jez
I am working on some perl stuff at the moment and it been a while so maybe i am being really stupid here, but...
I want to shuffle an array. i.e. take one item off the top and but it back on the bottom.
I thought that the difference between shift and pop was which end of the array they get the element from (and of course the same with unshift and push).
So my code is as follows....
sub randomSector{
@array = @_;
$arrayElementToMove = shift(@array);
push(@array, $arrayElementToMove);
my $retString = join(', ', @array);
return $retString;
}
But this seems to put it right back where i got it from.. not on the other end of the array.
Any help greatly appreciated!
Thanks
Jez