Hi James

James Kipp wrote:
> 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.
> Thanks
>
> $user = "jsmith";
> my %lookup = (
>         'jsmith' => "jsmith1",
>         'djones'  => "djones2",
>         'tday'  => "tday3",
> );
>
> for my $key (keys %lookup) {
> print "$lookup{$key}\n" if $key == $user;
> }

Ed is right, this should be 'if $key eq $user', but you're not using
the hash as it should be used. This is similar to accessing array
element 83 as follows:

    my $index =83;
    for my $i (0 .. $#array)
    {
        print $array[$i] if $i == $index;
    }

You can just do:

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

HTH,

Rob





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

Reply via email to