On Tue, 28 Jan 2003, Rob Dixon wrote:
> >
> > $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";
>
And you might was well design something that scales while
you're at it:
=-=-=-=-=-=-=-
%user = ("jsmith" => 1, "djones" => 1);
my %lookup = (
'jsmith' => "jsmith1",
'djones' => "djones2",
'tday' => "tday3",
);
for my $key (keys %lookup) {
print "$lookup{$key}\n", if defined $user{$key};
}
=-=-=-=-=-=-=-
jab
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]