in reply to Array shuffle code produces 'Modification of non-creatable array value attempted' error
use warnings; use strict; use Data::Dumper; my $arr = [1..5]; shuffle($arr); print Dumper($arr); sub shuffle { my $array = shift; my $i = @$array; while ( --$i ) { my $j = int rand( $i+1 ); @$array[$i,$j] = @$array[$j,$i]; } } __END__ $VAR1 = [ 3, 5, 4, 1, 2 ];
What version of Perl? How do you call the sub?
See also List::Util::shuffle
|
|---|