# This takes a player, then determines a valid game pairing. It #returns the opponent's name if there is one, otherwise # it returns undef. sub find_paring($white_player){ my $white_player = $_[0]; my $black_player = "none"; # Get a list of players still in the running my @possible_opponents = keys %{$matches_remaining{$white_player}}; # Shuffle the list to add some randomness, then find the first # avaliable opponent. &shuffle(\@possible_opponents); PAIRING: foreach $black_player (@possible_opponents){ # Once we have a valid match, we remove the entries from the # match hash, and return the pair. if (exists $matches_remaining{$black_player}{$white_player}){ delete $matches_remaining{$white_player}{$black_player}; delete $matches_remaining{$black_player}{$white_player}; last PAIRING; } } # Return the info we have return ($white_player, $black_player); }