At 7:37 AM -0600 11/6/11, Chris Stinemetz wrote:
I would like to join the key from %cell hash to %cbr hash
the dump from %cell hash looks like:
'65' => {
'CDM 1, 2, CBR 3, 15MHz' => 2
},
%cell is a two-level hash with two keys needed to get to hash value.
In the above snippet, the keys are $key1 = '65' and $key2 = 'CDM 1,
2, CBR 3, 15MHz', and the value of $cell{$key1}{$key2} is 2.
and the dump from %cbr looks like:
$VAR1 = {
'1' => 223,
};
%cbr as shown above is a single-level hash using only key '1' with
value of 223.
So that %cbr becomes:
'65'=>{
'1'=>3
};
If you want to make %cbr a two-level hash, then save the key you used
for %cell and use it along with the third key that is extracted from
the CBR substring:
$cbr{$key1}{$key3}++;
The portion of code that I am trying to complete this task is below. I'm
still learning complex data structures so please forgive my question if it
seems awkward.
my %cell;
my %heh_type_count;
my %cbr;
my $timeStamp;
my $hour;
while (my $line = <$FIN>){
if ($line =~ m|\d{1,2}/\d{1,2}/\d{2} ((\d{1,2}):\d{1,2}:\d{1,2})|){
$timeStamp = $1;
$hour = $2;
}
if ($line =~ /CELL\s*(\d+)\s*(.*),\s*HEH/){
if ((0 <=$hour)&&($hour <=23)){
# save the key for later use
my $key1 = $1;
$cell{$1}{$2}++;
$heh_type_count{$2}++;
if ($2 =~ /CBR\s*(\d+)/){
$cbr{$1}++; ## this is where I would like to join so the key from
%cell is present.
# use the saved key
$cbr{$key1}{$1}++;
}
}
}
}
print Dumper \%cell;
print Dumper \%cbr;
print Dumper \%heh_type_count;
You should give the saved key a more descriptive name than $key1.
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/