hi mwb613,
..Is it possible to use hash reference as a key in another hash reference?..

Ordinarily, maybe not! (But that is a 'white' lie) ;) Until you consider module like Tie::RefHash, which allows you use reference as hash key.

use strict; use warnings; use Data::Dumper; use Tie::RefHash; tie my %h, "Tie::RefHash"; my $key_hash_1 = { 'day' => 1, 'month' => 1, 'year' => 2000, 'hour' => 4, 'minute' => + 44 }; my $key_hash_2 = { 'day' => 1, 'month' => 1, 'year' => 2000, 'hour' => 4, 'minute' => + 45 }; %h = ( $key_hash_1 => { 'burgers_sold' => 5, 'fries_sold' => 3, 'sodas_sold' => 11 }, $key_hash_2 => { 'burgers_sold' => 2, 'fries_sold' => 4, 'sodas_so +ld' => 7 } ); print Dumper( $key_hash_1, $key_hash_2 ); print Dumper( \%h ); for ( keys %h ) { print join ' ' => %{$_}, ' => ', %{ $h{$_} }, $/; }
Output:
$VAR1 = { 'hour' => 4, 'minute' => 44, 'month' => 1, 'day' => 1, 'year' => 2000 }; $VAR2 = { 'hour' => 4, 'minute' => 45, 'month' => 1, 'day' => 1, 'year' => 2000 }; $VAR1 = { 'HASH(0x8e963e0)' => { 'fries_sold' => 3, 'sodas_sold' => 11, 'burgers_sold' => 5 }, 'HASH(0x8eb01d0)' => { 'fries_sold' => 4, 'sodas_sold' => 7, 'burgers_sold' => 2 } }; hour 4 minute 44 month 1 day 1 year 2000 => fries_sold 3 sodas_sold +11 burgers_sold 5 hour 4 minute 45 month 1 day 1 year 2000 => fries_sold 4 sodas_sold +7 burgers_sold 2
Secondly, I think where you are using chains of while loops, a for loop would have been better.

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

In reply to Re: Use a hashref as a key in another hashref? by 2teez
in thread Use a hashref as a key in another hashref? by mwb613

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.