| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#=============================================== |
|
2
|
|
|
|
|
|
|
package Banal::Utils::Hash; |
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
1756
|
use 5.006; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
41
|
|
|
5
|
1
|
|
|
1
|
|
73
|
use utf8; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
7
|
|
|
6
|
1
|
|
|
1
|
|
24
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
36
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
30
|
|
|
8
|
1
|
|
|
1
|
|
5
|
no warnings qw(uninitialized); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
123
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Exporter; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw(get_inner_hash_value); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
6
|
use Scalar::Util qw(reftype); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
211
|
|
|
17
|
1
|
|
|
1
|
|
7
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
459
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
#----------------------------------------------- |
|
21
|
|
|
|
|
|
|
# get_inner_hash_value($hash, @$keys) -- Given a list of keys, get the associated "value" in an inner hash. |
|
22
|
|
|
|
|
|
|
# Assumes that all inner levels (except the obtained value) are also HASH references. |
|
23
|
|
|
|
|
|
|
#............................................... |
|
24
|
|
|
|
|
|
|
# Function (NOT a method) |
|
25
|
|
|
|
|
|
|
#----------------------------------------------- |
|
26
|
|
|
|
|
|
|
sub get_inner_hash_value { |
|
27
|
0
|
|
|
0
|
1
|
|
my $hash = shift; |
|
28
|
0
|
|
|
|
|
|
my $keys = [@_]; |
|
29
|
0
|
|
|
|
|
|
my $key = pop @$keys; |
|
30
|
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
my $h = $hash; |
|
32
|
0
|
|
|
|
|
|
foreach my $k (@$keys) { |
|
33
|
0
|
0
|
|
|
|
|
return undef unless (reftype($h) eq 'HASH'); |
|
34
|
0
|
0
|
|
|
|
|
if (exists ($h->{$k})) { |
|
35
|
0
|
|
|
|
|
|
$h = $h->{$k}; |
|
36
|
|
|
|
|
|
|
}else { |
|
37
|
0
|
|
|
|
|
|
return undef; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
if (exists ($h->{$key})) { |
|
42
|
0
|
|
|
|
|
|
return $h->{$key}; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
0
|
|
|
|
|
|
return undef; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
__END__ |