Hi,
I have a small hash of directory values. When a user inputs a
directory value I want to check to see if this directory value is in
my hash. If it is not the requested function will be denied. My
problem is that when I iterate over the hash I get answers for every
key in the hash. so in my example below if I enter "/usr/bin I will
get a "match found" and "no match found". What I want is to only get
a "no match found error if the value is never found in the hash. I
tried using "exists" but this seems to check for the existence of a
key not a value, and the user will input the value.
thanks in advance for any hints.
-Angus
#!/usr/bin/perl
use strict;
use warnings;
print "enter path:";
chomp (my $dir = <STDIN>);
my %directory_hash = ("dir1" => "/usr/bin",
"dir2" => "/users/home",);
foreach my $value ( values %directory_hash) {
unless ($value eq $dir) {
print "no match found!\n";
last;
}
print "match found\n"
}