title: How to have a perl variable act as a hash and an object?
body: <p>In perl, I'm trying to create a variable <code>$foo</code> that I can do both of the following on:</p>
  
  <pre><code>$foo-&gt;getBirthday();     # (A)
  $foo-&gt;{'name'};          # (B)
  </code></pre>
  
  <p>How can I do this?</p>
  
  <p>I understand that if I create a perl object then I can have a getBirthday subroutine, but if I do that; how can I use the <code>-&gt;{'name'}</code> syntax also?  Similarly, if I create a basic perl hash reference, then I can do B, but I don't know how I would accomplish A.</p>
  
  <p>Can someone show me how to create a data structure/object that allows both these syntaxes?</p>
  
  <p>I'm pretty sure this is legal in some fashion since I've seen it in other people's code.  (Unfortunately, its not possible for me to look through their source or run their program)</p>