in reply to Re: Case insensitive hash keys
in thread Case insensitive hash keys
This looks like a perfect solution. However it does require you to download and install a module from CPAN - since Hash::Case::Preserve is not included in the standard perl distribution.
An alternative would be to pick a case(either upper or lower) to load your hash keys in as - then as you load key/value combinations into the hash, convert your hash key to either upper or lower case(whichever you picked) *before* you load them into the hash. Then when you go to refer to a specific key in the hash, first convert the key to the same case that you loaded them in. This technique will have the same effect as ignoring case. There is no other way that I know of to ignore the case of hash keys.
HTH.Example: my %myhash = (); my $key1 = "MixedCase"; my $lower_key1 = lc($key1); $myhash{$lower_key1} = "Some Value"; if (exists($myhash{lc("MIXEDCASE")})) { print "YES it exists!\n"; } else { print "NO it doesn't exist!\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Case insensitive hash keys
by jonadab (Parson) on Feb 06, 2004 at 14:04 UTC |