I have 2 hashes and I am comparing both the hashes. First I check if the Key from hash2 exists in the hash1 and then compare the values.
So the question is how do I ignore case when comparing the Hash keys in the below example code.
#! /usr/bin/perl
#
%hash1 = ("John", 43, "Paul", 25, "Marie", 22);
%hash2 = ("john", 43, "Paul", 25, "marie", 22);
while (($KEY_2, $VALUE_2) = each %hash2){
if (exists $hash1{$KEY_2}){
print "$KEY_2 : Matched\n";
}
else{
print "$KEY_2 : Did not match\n";
}
}
In the above example, John does not match with john as keys have different case. How do I ignore case when comparing the keys in the above example?
Here is the output of the script when you run it
john : Did not match
Paul : Matched
marie : Did not match
Your help is much appreciated.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.