in reply to Re^3: working with hashes of arrays
in thread working with hashes of arrays

Describe the problem you are trying to solve. My mind reading ability is limited and somewhat spasmodic.


Perl's payment curve coincides with its learning curve.

Replies are listed 'Best First'.
Re^5: working with hashes of arrays
by gman1983 (Novice) on Dec 02, 2008 at 02:48 UTC
    use strict; use warnings; my @hand3 = qw/KsQs JsAs/; my @hand4 = qw/AsKc 2s3s/; my @hand899 = qw/As3c/; my @handsLists = (\@hand3, \@hand4, \@hand899); ##Set my hand my $my_pocket = "AcAs"; #My cards my %pocketCards = map {$_ => 0} $my_pocket =~ /(.{2})/g; printf join '', keys %pocketCards, "\n\n"; for my $hands (@handsLists) { # If either pocket card matches the first hand card omit the hand @$hands = grep {! exists $pocketCards{substr ($_, 0, 2)}} @$hands; print "@$hands\n"; }
    Prints:
    KsQs JsAs 2s3s
    I need it to say:
    KsQs 2s3s
    It any of the cards in my hand are found in either of my opponents cards, then the whole hands needs to be removed from it's @hand?.
      use strict; use warnings; my @hand3 = qw/KsQs JsAs/; my @hand4 = qw/AsKc 2s3s/; my @hand899 = qw/As3c/; my @theirHands = (\@hand3, \@hand4, \@hand899); my $myHand = "AcAs"; my %myCards = map {$_ => 0} $myHand =~ /(.{2})/g; print "My hand: ", join '', keys %myCards, "\n"; for my $hands (@theirHands) { # If any of my cards match an opposing hands' card, reject the opp +osing hand my @retained; for my $hand (@$hands) { next if grep {exists $myCards{$_}} $hand =~ /(.{2})/g; push @retained, $hand; } print "@retained\n"; }

      Prints:

      My hand: AsAc KsQs 2s3s

      Perl's payment curve coincides with its learning curve.