in reply to Array shuffle code produces 'Modification of non-creatable array value attempted' error

Works for me when I pass it a reference to a simple array on Perl version 5.12.2:
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

  • Comment on Re: Array shuffle code produces 'Modification of non-creatable array value attempted' error
  • Download Code