in reply to Re: randomize array
in thread randomize array

If you are expecting the statement ... to interchange the elements, you are missing a step or two.
No, that part works fine:
my @usernames = qw(zero one two three four five six); testswap(\@usernames); print join(" ", @usernames), "\n"; sub testswap { my $array = shift; my $i = 2; my $j = 5; @$array[$i, $j] = @$array[$j, $i]; }
Prints: zero one five three four two six

As runrig pointed out, you're not returing a value, you could put return $array->[0] at the end of the subroutine.

If you just want to pick one element out of the list, you're going to too much trouble. You can just say:

my $username = $usernames[rand(@usernames)];