in reply to Randomize word
#!/usr/bin/perl use strict; my @word_array = split '', "iguana"; fisher_yates_shuffle(\@word_array); print "Word is ", join ('', @word_array), "\n"; # From perldoc -q shuffle: 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]; } }
I would like to know if there's a simple way to remove the extraneous @word_array variable. Maybe I'm just overtired, but I couldn't see a way to get an array reference from the return of the split...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Randomize word
by BrowserUk (Patriarch) on Sep 07, 2004 at 13:18 UTC | |
by Nkuvu (Priest) on Sep 08, 2004 at 01:43 UTC | |
by BrowserUk (Patriarch) on Sep 08, 2004 at 02:15 UTC |