Is it possible to check a variable against all the keys in a hashThe question suggests you do not understand the fundamental property of a hash.
The primary use of a hash is for a quick and simple lookup of a 'key', by indexing, using curly-braces.
The first line of your code:
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.if (! exists ($hash{$remoteIP})){
Your later comparison:
is a more expensive way of doing the same comparison that the first line does.if ($remoteIP ~~ @k){
"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." -Confucius
In reply to Re: Comparing a value to hash key
by NetWallah
in thread Comparing a value to hash key
by jaffinito43
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |