Hi EchoAngel,

If you want to find which elements are missing from a list, you've got to know the complete set of elements. I'm sure there's a better, more perlish way to do this (using grep, Quantum::Superpositions, Set::Scalar, Set::Bag?), but here is how I would do it.

First, create a list of all the fruits. I don't quite understand how your AA-ZZ fits in, but it looks like 'pearsWE' eq 'pearsDF' so I'll assume they are not part of the name (I'm creating a new hash without those characters for simplicity). It also looks like all the fruit names are in lowercase, so I'll go on that assumption as well. Second, cycle through each country and check to see which elements are missing from the list of fruits.

my ( %fruits, %newHASH ); # find all the fruit names foreach my $country ( keys %HASH ) { foreach my $fruit ( keys %{ $HASH{$country} } ) { $fruit =~ m/([a-z]+)[A-Z]+/; # [A-Z]+ included for distinction $fruits{$1}++; $newHASH{$country}{$1} = $HASH{$country}{$fruit}; } } # find which fruits are missing foreach my $country ( keys %newHASH ) { foreach my $fruit ( keys %fruits ) { if( not exists $newHASH{$country}{$fruit} ) { print "$country is missing $fruit!\n"; } } }

BTW, if you don't need a hash for the fruits, a hash of arrays might be more appropriate than a hash of a hash. In other words, instead of using:

%HASH $country $fruit = 1 $fruit = 1

you might consider:

%HASH $country = [ $fruit, $fruit... ]

(which might make comparing lists easier).

HTH


In reply to Re: Reporting empty cells in a table of records by bobf
in thread Reporting empty cells in a table of records by EchoAngel

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.