>Should be a simple question. I am trying to only print the element of the
> hash, that matches the $user string but it prints all of the elements.
What
> am I missing.

print "$lookup{$user}\n";

> Thanks
>
> $user = "jsmith";
> my %lookup = (
>         'jsmith' => "jsmith1",
>         'djones'  => "djones2",
>         'tday'  => "tday3",
> );
>
> for my $key (keys %lookup) {
>               print "$lookup{$key}\n" if $key == $user;
> }
>
> --
> prints:
> djones2
> tday3
> jsmith1

The reason it does this is you are using numeric comparison (==) instead
of string comparison (eq), and all of the keys are numerically equal to
$user.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to