![]() |
|
Keep It Simple, Stupid | |
PerlMonks |
removing arbitrary elements from an array?by Anonymous Monk |
on Mar 15, 2000 at 19:58 UTC ( #5424=perlquestion: print w/replies, xml ) | Need Help?? |
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question: I'm writing a program to simulate the shuffling of a deck of cards. So far it works fine, with one problem -- repeat cards keep turning up. Is there any way to cut an arbitrary value out of an array? The code works like this: while ($game_hand < 12) {$_ = int rand(@deck); push @hand, $_; $game_hand++; } I'd like a function that could cut whatever value $_ gets out of @deck completely, during the loop so I don't have to go through and check it for redundancy at a later point (and yes, I know about splice: for whatever reason, in this case it doesn't work and ends up giving me more repeat values... ugh).
Back to
Seekers of Perl Wisdom
|
|