in reply to Re: working with hashes of arrays
in thread working with hashes of arrays
my %array_of_lists = ('0' => [@list3], '1' => [@list4], '2' => [@list8 +99]); #my @array_of_lists = (@list3, @list4, @list899); ##Set my hand my $my_pocket = 'AcAd'; my ($key, $t); for $key ( 0 .. scalar(keys %array_of_lists)) { #The loop will iterate through each element (hand of current h +andlist) of the current row and remove any #hand that contains the cards assigned randomly above. for $t ( 0 .. scalar @{$array_of_lists{$key}} ) { #If the first card of the random hand above equal the firs +t card in the element I am currently on, then remove the element from + this handlist by #splicing it out. Or if the first card of the random hand +above equal the second card of the element (hand) I am currently spli +ce it out. if (substr($my_pocket, 0, 2) eq substr($array_of_lists{$ke +y}[$t], 0, 2)) { $array_of_lists{$key} = splice(@{$array_of_lists{$key} +}, $t, 1); } elsif (substr($my_pocket, 0, 2) eq substr($array_of_lists{ +$key}[$t], 2, 2)) { $array_of_lists{$key} = splice(@{$array_of_lists{$key} +}, $t, 1); } elsif (substr($my_pocket, 2, 2) eq substr($array_of_lists{ +$key}[$t], 0, 2)) { $array_of_lists{$key} = splice(@{$array_of_lists{$key} +}, $t, 1); } elsif (substr($my_pocket, 2, 2) eq substr($array_of_lists{ +$key}[$t], 2, 2)) { $array_of_lists{$key} = splice(@{$array_of_lists{$key} +}, $t, 1); } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: working with hashes of arrays
by graff (Chancellor) on Dec 02, 2008 at 03:02 UTC |