in reply to calling a hash

I think they are suggesting you should verify $bob has something in it. If you don't put a value in $bob, it creates a hash entry with the empty string. If you want a hash entry with the string 'bob', don't put the $ in front of it.

I think this would explain your results. Printing $random_name{$bob} is actually $random_name{''} and you are probably entering the string 'bob' at the prompt.

Try this to verify what you have in %random_name:

use Data::Dumper; print Dumper( \%random_name );

Replies are listed 'Best First'.
Re^2: calling a hash
by Anonymous Monk on Oct 04, 2005 at 13:26 UTC
    no sorry not the person who posted earlier. but i have resolved the problem, removing the $ in the hash corrected it Thanks for all of your help
      Indeed this is a situation in which turning on warnings would have solved the problem for you:
      $ perl -we '%a=($bob => "foo")' Name "main::a" used only once: possible typo at -e line 1. Name "main::bob" used only once: possible typo at -e line 1. Use of uninitialized value in list assignment at -e line 1.
      See in particular the last line. But then if had also turned on strict
      $ perl -Mstrict -e 'my %a=($bob => "foo")' Global symbol "$bob" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors.
      So, to put it briefly: do it!