line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hash::Search; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
27014
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
5
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
437
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my %hash_search_result = (); |
14
|
|
|
|
|
|
|
my $hash_search_result_count = 0; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new{ |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# new: create a new instance of |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
0
|
11
|
my $class = shift; |
21
|
1
|
|
|
|
|
2
|
my $self = {}; |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
5
|
return bless($self, $class); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub hash_search{ |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# hash_search: Find matches of names using the regular expression |
30
|
|
|
|
|
|
|
# and hash given. |
31
|
|
|
|
|
|
|
|
32
|
5
|
|
|
5
|
0
|
289
|
my $class = shift; |
33
|
5
|
|
|
|
|
8
|
my ($passed_hash, %passed_hash); |
34
|
0
|
|
|
|
|
0
|
my $passed_expression; |
35
|
5
|
|
|
|
|
6
|
my $regex_test = ""; |
36
|
|
|
|
|
|
|
|
37
|
5
|
|
|
|
|
7
|
$passed_expression = shift; |
38
|
5
|
|
|
|
|
18
|
(%passed_hash) = @_; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Check if the hash or the expression passed is blank and |
41
|
|
|
|
|
|
|
# write a carp message if blank. |
42
|
|
|
|
|
|
|
|
43
|
5
|
50
|
|
|
|
21
|
if (!%passed_hash){ |
44
|
0
|
|
|
|
|
0
|
carp("The hash given is blank"); |
45
|
0
|
|
|
|
|
0
|
return; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
5
|
50
|
33
|
|
|
31
|
if (!$passed_expression || $passed_expression eq ""){ |
49
|
0
|
|
|
|
|
0
|
carp("The expression given is blank"); |
50
|
0
|
|
|
|
|
0
|
return; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Process the hash given putting the results into a |
54
|
|
|
|
|
|
|
# seperate hash while increment the search result |
55
|
|
|
|
|
|
|
# counter. |
56
|
|
|
|
|
|
|
|
57
|
5
|
|
|
|
|
9
|
%hash_search_result = (); |
58
|
5
|
|
|
|
|
6
|
$hash_search_result_count = 0; |
59
|
|
|
|
|
|
|
|
60
|
5
|
|
|
|
|
15
|
foreach my $hash_key (keys %passed_hash){ |
61
|
|
|
|
|
|
|
|
62
|
25
|
100
|
|
|
|
136
|
if ($hash_key =~ m/$passed_expression/){ |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# We have a match so put the result into the hash. |
65
|
|
|
|
|
|
|
|
66
|
7
|
|
|
|
|
14
|
$hash_search_result{ $hash_key } = $passed_hash{$hash_key}; |
67
|
7
|
|
|
|
|
14
|
$hash_search_result_count++; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Return 1 if there was at least one search result returned and return |
73
|
|
|
|
|
|
|
# 0 if not. |
74
|
|
|
|
|
|
|
|
75
|
5
|
100
|
|
|
|
25
|
return 1 if $hash_search_result_count >= 1; |
76
|
1
|
|
|
|
|
5
|
return 0; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub hash_search_resultdata{ |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# hash_search_resultdata: Return the result data for |
83
|
|
|
|
|
|
|
# the search that has been made. |
84
|
|
|
|
|
|
|
|
85
|
7
|
|
|
7
|
0
|
43
|
return %hash_search_result; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub hash_search_resultcount{ |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# hash_search_resultcount: Return the count of results |
92
|
|
|
|
|
|
|
# for the search. |
93
|
|
|
|
|
|
|
|
94
|
6
|
|
|
6
|
0
|
38
|
return $hash_search_result_count; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__END__ |