in reply to Comparing two hashes for duplicate keys with no case sensitivity
You don't indicate why you need to do this so the following may be rather more than you need. However, this finds all case insensitive matching keys and reports them:
use strict; use warnings; my %hash1 = (TEXT => 25, Text => 25, Wibble => 20); my %hash2 = (text => 25, TexT => 25, wibble => 20); my %h1Keys; my %h2Keys; push @{$h1Keys{lc $_}}, $_ for keys %hash1; push @{$h2Keys{lc $_}}, $_ for keys %hash2; my @common = grep {exists $h2Keys{$_}} keys %h1Keys; print "Hash 1 keys \[@{$h1Keys{$_}}\] match \[@{$h2Keys{$_}}\] in hash + 2\n" for @common;
Prints:
Hash 1 keys [Wibble] match [wibble] in hash 2 Hash 1 keys [TEXT Text] match [text TexT] in hash 2
BTW, always use strictures (use strict; use warnings; - see The strictures, according to Seuss).
|
|---|