in reply to Wrong hash accessing?

You need to chomp your input.

When the user types "Word1" and then hits <ENTER>, that <ENTER> gets included in the input string as a "newline" ("\n"). So the input string looks like "Word1\n". There is no hash key named "Word1\n", only "Word1".

Or to put it another way, "Word1\n" and "Word1" would be two different keys.

This will work as you seem to intend:

while(<STDIN>) { chomp $_; # Remove the trailing newline from the contents of $_. my $name = $_; print "$p{$name}\n"; }

Dave

Replies are listed 'Best First'.
Re^2: Wrong hash accessing?
by Firsov (Novice) on Mar 18, 2015 at 05:34 UTC

    It is seems to be work. Thank you very much!