<?xml version="1.0" encoding="windows-1252"?>
<node id="1003750" title="Re: Comparing a value to hash key" created="2012-11-13 23:53:03" updated="2012-11-13 23:53:03">
<type id="11">
note</type>
<author id="159887">
NetWallah</author>
<data>
<field name="doctext">
&lt;blockquote&gt;
 &lt;i&gt; Is it possible to check a variable against all the keys in a hash&lt;/i&gt;
&lt;/blockquote&gt;
The question suggests you do not understand the fundamental property of a hash.&lt;p&gt;
The primary use of a hash is for a quick and simple lookup of a 'key', by indexing, using curly-braces.&lt;p&gt;
The first line of your code:
&lt;c&gt;
if (! exists ($hash{$remoteIP})){
&lt;/c&gt;
does exactly that - looks up the value of $remoteIP, and can be thought of as comparing with every possible key in %hash, and returning 'true' if  the matching one exists.&lt;p&gt;
Your later comparison:
&lt;c&gt;
    if ($remoteIP ~~ @k){
&lt;/c&gt;
is a more expensive way of doing the same comparison that the first line does.
&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-159887"&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;small&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
"By three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest."
 &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp; &amp;nbsp; -Confucius
&lt;/small&gt;&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
1003729</field>
<field name="parent_node">
1003729</field>
</data>
</node>
