title: How can I use a variable's value as a Perl variable name?
body: <p>Sorry about all these silly questions, I've been thrust into Perl programming and I'm finding it really hard to think like a Perl programmer.</p>
  
  <p>Silly question for today:
  I load a pipe delimited file into a hash using the id field as the key, like so</p>
  
  <pre><code>#open file
  
  my %hash;
  while (&lt;MY_FILE&gt;) {
      chomp;
  
      my ($id, $path, $date) = split /\|/;
  
      $hash{$id} = {
          "path" =&gt; $path,
          "date" =&gt; $date
      };
  }
  </code></pre>
  
  <p>There a few times, however, when I actually need the key to be the path because, for whatever reason (and no, it can't be changed) the id isn't unique, so I had the bright idea that I could put it all into a subroutine and pass the name of the variable to use as the key to it, kinda like so:</p>
  
  <pre><code>load_hash("path");
  
  sub load_hash {
      my $key = shift;
  
      #do stuff, and then in while loop
      $hash{${$key}} = #and so on
  }
  </code></pre>
  
  <p>but in perldb x ${$key} is always undef, although x ${path} prints the value in $path. </p>
  
  <p>Is there some way of doing what I'm trying to?</p>
  
  <p>TIA</p>