title: Printing return value from function in Perl
body: <p>How come the following works?</p>
  
  <pre><code>    print "Property is :" . $property-&gt;name("NODE_HOST") . "\n";
  </code></pre>
  
  <p>but not this:</p>
  
  <pre><code>    print "Property is : $property-&gt;$name("NODE_HOST")\n";
  </code></pre>
  
  <p>The compiler complains about the second snippet:</p>
  
  <pre><code>    Bareword found where operator expected at ./testProperties.pl line 11, near ""Property is : $property-&gt;$name("NODE_HOST"
      (Missing operator before NODE_HOST?)
  </code></pre>
  
  <p>Perl is normally pretty easy-going about taking shortcuts when printing out combinations of strings and variables. <code>$property-&gt;name</code> is a call to a class Property which returns the value of the name passed in:</p>
  
  <pre><code>    sub name {
         my ( $self, $propertyName ) = @_;
         my $hash_ref = $self-&gt;{_hashref};
         my %properties = %$hash_ref;
         my $property = $properties{$propertyName};
         return $property;
      }
  </code></pre>