title: How to access array element returned from a object method in perl?
body: <p>I have been using Perl for a while but is bothered by one syntax problem.
  In some packages, a method can return an array. For example</p>
  <pre><code>$root-&gt;getlist();
  </code></pre>
  <p>Will return an array. Now I want to get the first element of the result. Of course I can do this:</p>
  <pre><code>my @results = $root-&gt;getlist();
  if($results[0] =~ /wow/) {
      print &quot;Qualified result&quot;;
  }
  </code></pre>
  <p>However, this is very troublesome. Is there a way that I can combine the first line with second line? I tried this but failed.</p>
  <pre><code>if(${$root-&gt;getlist()}[0] =~ /wow/) {
      print &quot;Qualified result&quot;;
  }
  </code></pre>
  <p>Is there a way to do this quick?</p>
  <p>A better example:
  Consider this following package:</p>
  <pre><code>package Try;
  
  sub new {
      my $package = shift;
      return bless({}, $package);
  }
  
  sub getList {
      return (1,2,3,4,5);
  }
  
  1;
  </code></pre>
  <p>Now I have a user pl file like this:</p>
  <pre><code>use lib '.';
  use Try;
  use strict;
  
  my $obj = Try-&gt;new();
  print ($obj-&gt;getList())[0];
  </code></pre>
  <p>Trying to run this script will result in:</p>
  <blockquote>
  <p>syntax error at perlarrayaccess.pl line 6, near &quot;)[&quot;</p>
  <p>Execution of perlarrayaccess.pl aborted due to compilation errors.</p>
  </blockquote>