go ahead... be a heretic | |
PerlMonks |
unsorted listby thekestrel (Friar) |
on Apr 24, 2005 at 06:16 UTC ( [id://450883]=perlquestion: print w/replies, xml ) | Need Help?? |
thekestrel has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
I'm running a number of operations on a set of data, but I want the list of data to be in a random order each time i process it. $stuff = [ 'cat', 'dog', 'pig', 'cow' ]; and running through the list would give random combinations... i.e. What I want to ask advice for is what is the fastest/most efficient way to do this? Is there some neat equivalent of sort that equates to unsort. I was thinking of having either a hash or array and picking a value from the list then removing that selection and repeating until the list was empty each iteration, but that seems a little unwheeldly. I don't want any of the values repeated from the list i.e. dog dog cat pig, so just doing a rand on the size of my list is not what I'm after to select the elements. Regards Paul.
Back to
Seekers of Perl Wisdom
|
|