in reply to random index in array - no duplicates

This is overly verbose, but that's okay. Basically I'm making a copy of the array, iterating over the original array $#array times, and removing the randomly selected element from the copy on each iteration.

That means that each element is used only once and that the resulting array is basically a randomized version of the input array.

#!/usr/bin/perl @arr=("1","2","3","4"); @sub=@arr; foreach (@arr){ $slot = int(rand(@sub)); ($new) = splice(@sub,$slot,1); push(@newarr,$new); } foreach (@newarr){ print "$_\n"; }
And then scrunch up that code a little:
$hold=@arr; foreach (0...$hold){ push(@newarr, splice(@arr,int(rand(@arr)),1)); }
Still seems inelegant though . . . hmmmm.
-oakbox