in reply to working with hashes of arrays

If I understand what you are trying to do correctly then an array is the appropriate data structure. Consider:

use strict; use warnings; my @hand3 = qw/KsQs Js0s/; my @hand4 = qw/AsKc 2s3s/; my @hand899 = qw/1s3c/; 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:

AsAc KsQs Js0s 2s3s 1s3c

Note the use of grep with a hash to check the first card in each hand in the list against the pocket cards which tidies the code up something wonderful.

Note too that the variables describe what they contain rather than what manner of data structure they are - that makes understanding what's going on much easier. The context and syntax tell you what the data structure is, but something else has to tell you what the data is.


Perl's payment curve coincides with its learning curve.

Replies are listed 'Best First'.
Re^2: working with hashes of arrays
by gman1983 (Novice) on Dec 02, 2008 at 02:23 UTC
    Grandfather, I can't thank you enough, that is awesome. I can't tell you how much I owe you. Thanks, gman
      How do I do it with both cards?

        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.