in reply to Comparing two hashes for duplicate keys with no case sensitivity
You already loop through every key of %hash1, so you don't need to check in the hash again
%hash1 = ("TEXT", 25); %hash2 = ("text", 25); foreach $item1 (keys(%hash1)) { foreach $item2 (keys(%hash2)) { if (lc $item1 eq lc $item2}) { print "matches\n";} } }
By the way, as long as your hashes are small (say <200 entries) or time is not important, your algorithm is fine, but if not, then you might generate a second hash with the lowercase keys of one of the hashes and then check the second hash against that:
%hash1 = ("TEXT", 25); %hash2 = ("text", 25); foreach $item1 (keys(%hash1)) { $lchash1{lc $item1}=1; } foreach $item2 (keys(%hash2)) { if (exists $lchash1{lc $item2}) { print "matches\n";} } }
|
|---|