Here's a Tie module you can use to recursively implement the
Tie::CaseInsensitive module on hash values that are hash
references (so you don't need to keep tie()ing).
package Tie::RecursiveCI;
use strict;
use Tie::CaseInsensitive;
use vars qw( @ISA );
@ISA = qw( Tie::CaseInsensitive );
sub STORE {
my ($self, $key, $value) = @_;
$self->{lc $key} = $value;
if (UNIVERSAL::isa($value,'HASH')) {
tie %{ $self->{lc $key} }, 'Tie::RecursiveCI';
}
return $self->{lc $key};
}
Here's a sample program using it:
#!/usr/bin/perl
use Tie::RecursiveCI;
tie %hash, 'Tie::RecursiveCI';
$hash{foo} = 10;
$hash{Foo} = 20;
$hash{bar}{blat} = 30;
$hash{BAR}{blAT} = 40;
for (sort keys %hash) {
print "$_ => $hash{$_}\n";
}
for (sort keys %{ $hash{bAr} }) {
print "$_ => $hash{bar}{$_}\n";
}
And here's the output:
bar => HASH(0xd67b0)
foo => 20
blat => 40
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.