Hello rshoe, and welcome to the Monastery!
You’re nearly there! You just need to move the line:
chomp $fruit;
to before the line:
my $fruits = $fruit_num{$fruit};
in which you access the hash. Why? After $fruit has been assigned the user’s input, its final character is a newline. With the newline still present, the hash lookup fails because the key apple\n is not the same as the key apple. chomp removes the trailing newline, so the user’s input then matches a hash key, and the hash lookup succeeds.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: Hash from prompt
by Athanasius
in thread Hash from prompt
by rshoe
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |