title: How Does One Use a Variable as a Hash Key in Perl?
body: <p>I've been struggling with assigning as variable to a key in Perl. What I'm trying to do is prompt the user to input a value to be held in a variable that is used as a key to access and print a value held in a hash table. The following code helps illustrate my problem:</p>
  
  <pre><code>my $key = 0;
  print( "Enter the value for your key\n" );
  $key = &lt;&gt;;
  my %hash = (
     a =&gt; "A",
     b =&gt; "B",
  );
      print( $hash{$key} );
  </code></pre>
  
  <p>The problem is that print( $hash{$key} ); prints nothing to the screen, yet printf( $hash{"a"}; does; I do not understand that. Any help and clarification will be greatly appreciated. Thanks in advance.</p>