in reply to Re: Re^2: When the Best Solution Isn't
in thread When the Best Solution Isn't

There was a recent thread on the ActiveState list which was never quite solved. In general it came down to assigning to @_ was causing some weirdness to occur and ActiveState perl 5.6.1 would slow down to a crawl after a few thousand iterations. Other perls like my OpenBSD 5.6.1 and Cygwin 5.8.0 behaved nicely.

I'm not sure what the issue was but there may be lurking bug in assigning to @_. I'm warning against it. (or at least be aware so if you do run into trouble later...)

Update: fixed some spelling

  • Comment on Re: Re: Re^2: When the Best Solution Isn't

Replies are listed 'Best First'.
Re: Re: Re: Re^2: When the Best Solution Isn't
by japhy (Canon) on Sep 23, 2002 at 14:12 UTC
    Don't fret -- an equally speedy solution is thus:
    sub shuffle (\@) { my $d = shift; my @r = map rand, 0 .. $#$d; @$d[sort { $r[$a] <=> $r[$b] } 0 .. $#$d] = @$d; }
    It requires you send it an actual array, of course, but it is just as fast.

    Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;