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.

In reply to Re: working with hashes of arrays by GrandFather
in thread working with hashes of arrays by gman1983

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.