| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
|
2
|
|
|
|
|
|
|
package Tie::CPHash; |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# Copyright 1997-2012 Christopher J. Madsen |
|
5
|
|
|
|
|
|
|
# |
|
6
|
|
|
|
|
|
|
# Author: Christopher J. Madsen |
|
7
|
|
|
|
|
|
|
# Created: 08 Nov 1997 |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify |
|
10
|
|
|
|
|
|
|
# it under the same terms as Perl itself. |
|
11
|
|
|
|
|
|
|
# |
|
12
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful, |
|
13
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the |
|
15
|
|
|
|
|
|
|
# GNU General Public License or the Artistic License for more details. |
|
16
|
|
|
|
|
|
|
# |
|
17
|
|
|
|
|
|
|
# ABSTRACT: Case preserving but case insensitive hash table |
|
18
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
require 5.000; |
|
21
|
2
|
|
|
2
|
|
50086
|
use strict; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
76
|
|
|
22
|
|
|
|
|
|
|
#use warnings; # Wasn't core until 5.6.0 |
|
23
|
2
|
|
|
2
|
|
10
|
use vars qw($VERSION); |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
799
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#===================================================================== |
|
26
|
|
|
|
|
|
|
# Package Global Variables: |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$VERSION = '1.06'; |
|
29
|
|
|
|
|
|
|
# This file is part of Tie-CPHash 1.06 (November 9, 2013) |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#===================================================================== |
|
32
|
|
|
|
|
|
|
# Tied Methods: |
|
33
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
|
34
|
|
|
|
|
|
|
# TIEHASH classname |
|
35
|
|
|
|
|
|
|
# The method invoked by the command `tie %hash, classname'. |
|
36
|
|
|
|
|
|
|
# Associates a new hash instance with the specified class. |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub TIEHASH |
|
39
|
|
|
|
|
|
|
{ |
|
40
|
1
|
|
|
1
|
|
17
|
bless {}, $_[0]; |
|
41
|
|
|
|
|
|
|
} # end TIEHASH |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
|
44
|
|
|
|
|
|
|
# STORE this, key, value |
|
45
|
|
|
|
|
|
|
# Store datum *value* into *key* for the tied hash *this*. |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub STORE |
|
48
|
|
|
|
|
|
|
{ |
|
49
|
3
|
|
|
3
|
|
257
|
$_[0]->{lc $_[1]} = [ $_[1], $_[2] ]; |
|
50
|
|
|
|
|
|
|
} # end STORE |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
|
53
|
|
|
|
|
|
|
# FETCH this, key |
|
54
|
|
|
|
|
|
|
# Retrieve the datum in *key* for the tied hash *this*. |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub FETCH |
|
57
|
|
|
|
|
|
|
{ |
|
58
|
3
|
|
|
3
|
|
830
|
my $v = $_[0]->{lc $_[1]}; |
|
59
|
3
|
100
|
|
|
|
17
|
($v ? $v->[1] : undef); |
|
60
|
|
|
|
|
|
|
} # end FETCH |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
|
63
|
|
|
|
|
|
|
# FIRSTKEY this |
|
64
|
|
|
|
|
|
|
# Return the (key, value) pair for the first key in the hash. |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub FIRSTKEY |
|
67
|
|
|
|
|
|
|
{ |
|
68
|
1
|
|
|
1
|
|
442
|
my $a = scalar keys %{$_[0]}; |
|
|
1
|
|
|
|
|
4
|
|
|
69
|
1
|
|
|
|
|
4
|
&NEXTKEY; |
|
70
|
|
|
|
|
|
|
} # end FIRSTKEY |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
|
73
|
|
|
|
|
|
|
# NEXTKEY this, lastkey |
|
74
|
|
|
|
|
|
|
# Return the next (key, value) pair for the hash. |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub NEXTKEY |
|
77
|
|
|
|
|
|
|
{ |
|
78
|
2
|
|
|
2
|
|
4
|
my $v = (each %{$_[0]})[1]; |
|
|
2
|
|
|
|
|
7
|
|
|
79
|
2
|
100
|
|
|
|
16
|
($v ? $v->[0] : undef ); |
|
80
|
|
|
|
|
|
|
} # end NEXTKEY |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
|
83
|
|
|
|
|
|
|
# SCALAR this |
|
84
|
|
|
|
|
|
|
# Return bucket usage information for the hash (0 if empty). |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub SCALAR |
|
87
|
|
|
|
|
|
|
{ |
|
88
|
4
|
|
|
4
|
|
11
|
scalar %{$_[0]}; |
|
|
4
|
|
|
|
|
22
|
|
|
89
|
|
|
|
|
|
|
} # end SCALAR |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
|
92
|
|
|
|
|
|
|
# EXISTS this, key |
|
93
|
|
|
|
|
|
|
# Verify that *key* exists with the tied hash *this*. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub EXISTS |
|
96
|
|
|
|
|
|
|
{ |
|
97
|
2
|
|
|
2
|
|
313
|
exists $_[0]->{lc $_[1]}; |
|
98
|
|
|
|
|
|
|
} # end EXISTS |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
|
101
|
|
|
|
|
|
|
# DELETE this, key |
|
102
|
|
|
|
|
|
|
# Delete the key *key* from the tied hash *this*. |
|
103
|
|
|
|
|
|
|
# Returns the old value, or undef if it didn't exist. |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub DELETE |
|
106
|
|
|
|
|
|
|
{ |
|
107
|
2
|
|
|
2
|
|
241
|
my $v = delete $_[0]->{lc $_[1]}; |
|
108
|
2
|
100
|
|
|
|
13
|
($v ? $v->[1] : undef); |
|
109
|
|
|
|
|
|
|
} # end DELETE |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
|
112
|
|
|
|
|
|
|
# CLEAR this |
|
113
|
|
|
|
|
|
|
# Clear all values from the tied hash *this*. |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub CLEAR |
|
116
|
|
|
|
|
|
|
{ |
|
117
|
1
|
|
|
1
|
|
3
|
%{$_[0]} = (); |
|
|
1
|
|
|
|
|
5
|
|
|
118
|
|
|
|
|
|
|
} # end CLEAR |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
#===================================================================== |
|
121
|
|
|
|
|
|
|
# Other Methods: |
|
122
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
|
123
|
|
|
|
|
|
|
# Return the case of KEY. |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub key |
|
126
|
|
|
|
|
|
|
{ |
|
127
|
2
|
|
|
2
|
0
|
241
|
my $v = $_[0]->{lc $_[1]}; |
|
128
|
2
|
100
|
|
|
|
13
|
($v ? $v->[0] : undef); |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
#===================================================================== |
|
132
|
|
|
|
|
|
|
# Package Return Value: |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1; |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
__END__ |