What happened when you ran your code? What happens when you run this simplified version:
Why does the @reordered array always end up with a single element of 0? (Update: What do you get if you dump @lines after shuffling, and why?)c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "sub shuffle { my $array = shift; my $i; for ($i = @$array; --$i; ) { my $j = int rand ($i+1); next if $i == $j; @$array[$i,$j] = @$array[$j,$i]; } } ;; my @lines = qw(foo bar baz quux); my @reordered = shuffle(\@lines); dd \@reordered; " [0]
In reply to Re: shuffle a text file
by AnomalousMonk
in thread shuffle a text file
by salma
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |