A hash can't have multiple keys. A hash only has a single level of keys, but the values of those keys can point to other hashes.

You have a hash called %hash that is keyed by $loginId. The values in this hash point to other hashes (each value is a completely separate hash) that are all keyed by $month. It's an important point to understand.

I find that I can help myself remember this by using the -&gt; operator. This reminds me I'm talking about references and not merely other keys.

For example, instead of writing this:

$hash{$loginId}{$month} = $hash{$loginId}{$month} + $time1;


I would have write this:

$hash{$loginId}-&gt;{$month} = $hash{$loginId}-&gt;{$month} + $time1;


It's not much, but it's a good reminder that $month are keys to a hash reference and I need to dereference that hash before I can see its values. 

Let's take a simple loop that prints out %hash:

for my $loginId ( sort keys %hash ) {
    print qq(\$hash{$loginId} = "$hash{$loginId}"\n";
}


This will print out something like this:

$hash{bob} = "HASH(0x7f8e3b804ee8)"
$hash{david} = "HASH(0x...)"
$hash{sue} = "HASH(0x...)"


The HASH{0x...) are addresses to a hash reference. I need to dereference that hash to get the values:

for my $loginId ( sort keys %hash ) {
    my %months = %{ $hash{$loginId) };  # Dereferencing the hash;
}


Now, that I've dereferenced the hash, I can print out the months for each user:

for my $loginId ( sort keys %hash ) {
    my %months = %{ $hash{$loginId) };
    for my $month ( sort keys %months ) {
        print qq(\$hash{$loginId}-&gt;{$month} = ) . $hash{$loginId}-&gt;{$month} . "\n";
    }
}


By the way, there's no reason I couldn't combine the referencing with the inner for loop:

for my $loginId ( sort keys %hash ) {
    for my $month ( sort keys %{ $hash{$loginId) } ) {
        print qq(\$hash{$loginId}-&gt;{$month} = ) . $hash{$loginId}-&gt;{$month} . "\n";
    }
}


It looks like you were trying for a quick dump of all of your data. To do that, you can use the Data::Dumper module:

use strict;
use warnings;
use feature qw(say);  # Better way to print than print

use Data::Dumper;

....
say Dumper \%hash;  #Prints out the entire data structure.


perl how to print out a hash with multiple keys?
Someone once told me that when Eliyahu HaNavi comes to a baby's bris, everyone who is presently there is forgiven for their sins. 

Does anyone know the source for this?
