Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: array problem

by gav^ (Curate)
on Mar 15, 2002 at 02:03 UTC ( #151887=note: print w/replies, xml ) Need Help??


in reply to array problem

A quick perldoc -q shuffle array gives:
How do I shuffle an array randomly?
Use this: # fisher_yates_shuffle( \@array ) : # generate a random permutation of @array in place sub fisher_yates_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]; } } fisher_yates_shuffle( \@array ); # permutes @array in place
Other points to consider:
  • What on earth are you trying to do to $#arr?
  • You probably don't want to use @arr in the subsitution
  • You probably don't want to reinvent the wheel when there are perfectly good templating modules such as HTML::Template and Text::Template
  • splice wants an integer offset, rand returns a fractional number
  • print $_ is the same as print
I'm sure I've missed a few things. Sorry to sound overly harsh but I'm trying to be constructive :)

gav^

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://151887]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2022-01-25 06:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (65 votes). Check out past polls.

    Notices?