On Apr 12, Ilmari Karonen said: >On Tue, 9 Apr 2002 [EMAIL PROTECTED] wrote: >> On Tue, Apr 09, 2002 at 01:49:01PM +0300, Ilmari Karonen wrote: >> > On Fri, 5 Apr 2002 [EMAIL PROTECTED] wrote: >> > > >> > > sub shuffle { >> > > for (my $i = @_; $i;) { >> > > my $j = rand $i --; >> > > @_ [$i => $j] = @_ [$j => $i] >> > > } >> > > @_; >> > > } >> > >> > It doesn't, unfortunately, allow for the idiom one expects from a >> > copy-and-shuffle function, namely >> > >> > my @shuffled = shuffle @original; >> >> It allows for: >> >> my @shuffled = shuffle 1 .. 10; > >Not very consistently, though: > > my @shuffled = shuffle 'A',2,3,4,5,6,7,8,9,10,'J','Q','K'; > Modification of a read-only value attempted at - line 4.
Then change my $i = @_ to my $i = @_ = @_ in the for loop. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ]