PROBLEM
I am trying to display a report with the use of hashes.
I am pulling in data from a flat-file which has customer
records that have a Fiscal Year date and trying to match it with some dates to get a combined result.

DESCRIPTION
Lets say my hash looks like this after i set it up:

%HoH = ( cat => { 'FY2003-Q2' => { 'this is the customers data => '1' }, 'FY2003-Q4' => { 'this is the customers data => '1' }, 'FY2004-Q1' => { 'this is the customers data => '1' }, 'FY2004-Q2' => { 'this is the customers data => '1' }, }, dog => { 'FY2003-Q2' => { 'this is the customers data => '1' }, 'FY2003-Q1' => { 'blah blah blah' => '1' }, }, catdog => { 'FY2004-Q1' => { 'blah blah blah' => '1' }, 'FY2004-Q2' => { 'blah blah blah' => '1' } } );

Now one of my subs takes the current date and gives me the next four quarters and i use these 5 dates to sort my data like:
my %date_slots = ( 1 => FY2003-Q2, 2 => FY2003-Q3, 3 => FY2003-Q4, 4 => FY2004-Q1, 5 => FY2004-Q2 );

Now once i got all my data and dates setup i have to print the them out. so far so good.
BUT for those dates that i dont have anything i have to print "no data". See here:
foreach $customer (keys %HoH) { print "$customer\n"; foreach $date (keys %{$HoH{$customer}} ) { print "\t\t$date"; foreach my $data (keys %{$cal{$customer}{$date}} ) { print " = $data\n"; } } }
This prints what ever is in my HoH hash.

cat FY2003-Q2 = blah blah blah FY2003-Q4 = blah blah blah FY2004-Q1 = blah blah blah FY2004-Q2 = blah blah blah dog FY2003-Q1 = blah blah blah FY2003-Q2 = blah blah blah catdog FY2004-Q1 = blah blah blah FY2004-Q2 = blah blah blah
But my goal is to take the %date_slots hash and match my HoH data
with it if no match then print "no data". something like:
cat FY2003-Q2 = blah blah blah FY2003-Q3 = no data FY2003-Q4 = blah blah blah FY2004-Q1 = blah blah blah FY2004-Q2 = blah blah blah dog FY2003-Q2 = blah blah blah FY2003-Q3 = no data FY2003-Q4 = no data FY2004-Q1 = no data FY2004-Q2 = no data catdog FY2003-Q2 = no data FY2003-Q3 = no data FY2003-Q4 = no data FY2004-Q1 = blah blah blah FY2004-Q2 = blah blah blah

Sorry for the lousy explanation, and thanks for your help.

"Learning is a treasure
that will follow its owner everywhere."
-Chinese proverb


In reply to Mix and Match Hashes by data67

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.