I have a hash of a hash that I would like to accumulate 'matching' keys with (if that makes sense?). Basically I am reading in some files to gather data and attempt to create some totals. The following code gets my HoH created but I’m not sure how to lookup matching sub keys in the second layer. The HoH basically looks like the following and I would like to add the 'value' when the 'second?' key matches. So $VAR2 contains '01:4928' in the first hash and $VAR2 contains the same key '01:4928' add the corresponding values for those keys. Please forgive the ugly code. Thanks in advance
$VAR1 = 'UE_RTB_H2H_TPS_20040127.DAT';
$VAR2 = {
'01:4928' => '00',
'00:4355' => '00',
'04:4060' => '00',
'03:2142' => '00',
'02:3251' => '00',
$VAR1 = 'UE_RTB_H2H_TPS_20040127.DAT';
$VAR2 = {
'01:4928' => '01',
'00:4355' => '02',
'04:4060' => '00',
'03:2142' => '01',
'02:3251' => '00',
'01:404' => '00',
'00:3020' => '00',
'00:2237' => '00',
'00:3020' => '00',
'00:2237' => '00',
foreach $current_tps_file (sort readdir(TPS))
{
my %total_hash;
if ($current_tps_file =~ /^$args{b}$args{n}\w+$tps_pre_date_name$arg
+s{d}$args{p}/)
{
# OK got a file that meets the match criteria above.
open (TPS_FILE, "$current_tps_file") || die "FILE NOT OPEN: $!";
print "READING: $current_tps_file ...\n";
my @lines=<TPS_FILE>; # each @line array contains 1 minute.
shift @lines;
foreach my $line (@lines[1..$#lines])
{
my @minute = (split (/ /, $line) );
my $current_time = $minute[0];
shift @minute;
pop @minute;
my $second = 0;
foreach my $count (@minute){
$second++;
my $key = $current_time . $second;
#print "$key";
$total_hash{$key} = $count;
$all_files{$current_tps_file} = \%total_hash;
}
}
}
close (TPS_FILE);
}
closedir (TPS);
print Dumper(%all_files);
UPDATE: basically I would like to be able to search for common keys like below but in a HoH instead of two different hashes?
my @common = ();
foreach (keys %hash1) {
push(@common, $_) if exists $hash2{$_};
}
BazB: use vanilla single quotes