djbiv has asked for the wisdom of the Perl Monks concerning the following question:
UPDATE: basically I would like to be able to search for common keys like below but in a HoH instead of two different hashes?$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);
my @common = (); foreach (keys %hash1) { push(@common, $_) if exists $hash2{$_}; }
BazB: use vanilla single quotes
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: HoH and accumulation
by tilly (Archbishop) on Jan 27, 2004 at 19:36 UTC | |
by djbiv (Scribe) on Jan 28, 2004 at 22:17 UTC | |
by tilly (Archbishop) on Jan 29, 2004 at 16:32 UTC | |
|
Re: HoH and accumulation
by dragonchild (Archbishop) on Jan 27, 2004 at 19:27 UTC |