1Hash::Case(3) User Contributed Perl Documentation Hash::Case(3)
2
3
4
6 Hash::Case - base class for hashes with key-casing requirements
7
9 Hash::Case
10 is a Tie::StdHash
11 is a Tie::Hash
12
14 use Hash::Case::Lower;
15 tie my(%lchash), 'Hash::Case::Lower';
16 $lchash{StraNGeKeY} = 3;
17 print keys %lchash; # strangekey
18
20 Hash::Case is the base class for various classes which tie special
21 treatment for the casing of keys. Be aware of the differences in
22 implementation: "Lower" and "Upper" are tied native hashes: these
23 hashes have no need for hidden fields or other assisting data struc‐
24 tured. A case "Preserve" hash will actually create three hashes.
25
26 The following strategies are implemented:
27
28 * Hash::Case::Lower (native hash)
29 Keys are always considered lower case. The internals of this module
30 translate any incoming key to lower case before it is used.
31
32 * Hash::Case::Upper (native hash)
33 Like the ::Lower, but then all keys are always translated into
34 upper case. This module can be of use for some databases, which do
35 translate everything to capitals as well. To avoid confusion, you
36 may want to have you own internal Perl hash do this as well.
37
38 * Hash::Case::Preserve
39 The actual casing is ignored, but not forgotten.
40
42 tie HASH, TIE, [VALUES,] OPTIONS
43 Tie the HASH with the TIE package which extends Hash::Case. The
44 OPTIONS differ per implementation: read the manual page for the
45 package you actually use. The VALUES is a reference to an array
46 containing key-value pairs, or a reference to a hash: they fill the
47 initial hash.
48
49 Examples:
50
51 my %x;
52 tie %x, 'Hash::Case::Lower';
53 $x{Upper} = 3;
54 print keys %x; # 'upper'
55
56 my @y = (ABC => 3, DeF => 4);
57 tie %x, 'Hash::Case::Lower', \@y;
58 print keys %x; # 'abc' 'def'
59
60 my %z = (ABC => 3, DeF => 4);
61 tie %x, 'Hash::Case::Lower', \%z;
62
63 addPairs PAIRS
64 Specify an even length list of alternating key and value to be
65 stored in the hash.
66
67 addHashData HASH
68 Add the data of a hash (passed as reference) to the created tied
69 hash. The existing values in the hash remain, the keys are adapted
70 to the needs of the the casing.
71
72 setHash HASH
73 The functionality differs for native and wrapper hashes. For
74 native hashes, this is the same as first clearing the hash, and
75 then a call to addHashData. Wrapper hashes will use the hash you
76 specify here to store the data, and re-create the mapping hash.
77
79 Hash::Case::Lower Hash::Case::Upper Hash::Case::Preserve
80
82 Mark Overmeer (mark@overmeer.net). All rights reserved. This program
83 is free software; you can redistribute it and/or modify it under the
84 same terms as Perl itself.
85
87 This code is beta, version 1.003
88
89 Copyright (c) 2002-2003 Mark Overmeer. All rights reserved. This pro‐
90 gram is free software; you can redistribute it and/or modify it under
91 the same terms as Perl itself.
92
93
94
95perl v5.8.8 2003-10-27 Hash::Case(3)