[sf-perl] randomize particular lines
Bart Alberti
bart at solozone.com
Mon Mar 6 17:35:54 PST 2006
Michael Budash wrote:
>On Mar 6, 2006, at 4:05 PM, Bart Alberti wrote:
>
>
>
>>Here is the idea I am working on.
>>Bart Alberti
>>
>>
>not very elegant, but this works for me: perhaps someone smarter than
>ird group
>fisher_yates_shuffle( \@{$lines{3}} );
>
># re-join the three groups
>my (@words, $last);
>for my $g (0..(scalar(@{$lines{1}})-1)) {
> for my $l (1..3) {
> if ($lines{$l}->[$g]) {
> push @words, $lines{$l}->[$g];
> }
> else {
> $last++;
> last;
> }
> }
> last if $last;
>}
>
>print "$_\n" foreach (@words);
>
>#--------------------------------
>sub fisher_yates_shuffle {
>#--------------------------------
> my $deck = shift; # $deck is a reference to an array
> my $i = @$deck;
> while ($i--) {
> my $j = int rand ($i+1);
> @$deck[$i,$j] = @$deck[$j,$i];
> }
>}
>
>
>isco-pm
>
>
>
YES indeed 4.17 in COOKBOOK page 121.
Bart Alberti
More information about the SanFrancisco-pm
mailing list