title: How can I access an scalar iside a hash atribute of a class in perl?
body: <p>I am still learning some object oriented perl and I am struggling a bit on how to access my classes.</p>
  
  <p>I've successfully created a class which one of its attributes is a hash. When I want print directly the value of a given key in this hash, the output is always blank. If I assign a new variable to the value of the hash, then I can print this variable.</p>
  
  <p>Toy example code:</p>
  
  <pre><code> sub new {  
      my($clas) = @_;
      my($self) = {}; 
  
      bless($self,$clas);
      $self-&gt;{age_record} = {};
      return($self);  
  } 
  </code></pre>
  
  <p>Imaginary code that fills up my hash</p>
  
  <pre><code>my $class-&gt;new("class");
  fill_hash($class);
  </code></pre>
  
  <p>Let's use Data::Dumper to see what's in the hash.</p>
  
  <pre><code>print Dumper $class-&gt;{age_record};
  $VAR1 = {
           'Rigobert' =&gt; 17,
           'Helene' =&gt; 42
         };
  </code></pre>
  
  <p>I get nothing if I print directly.</p>
  
  <pre><code> print $class-&gt;{age_record}{'Rigobert'};
  </code></pre>
  
  <p>But if I asign it first to a new variable, it works.</p>
  
  <pre><code>my $age = $class-&gt;{age_record}{'Rigobert'};
  print "Age is : $age\n";
  </code></pre>
  
  <p>I get </p>
  
  <pre><code>Age is : 17
  </code></pre>
  
  <p>What am I doing wrong when referencing the hash attribute?</p>