title: Is returning a whole array from a Perl subroutine inefficient?
body: <p>I often have a subroutine in Perl that fills an array with some information. Since I'm also used to hacking in C++, I find myself often do it like this in Perl, using references:</p>
  
  <pre><code>my @array;
  getInfo(\@array);
  
  sub getInfo {
     my ($arrayRef) = @_;
     push @$arrayRef, "obama";
     # ...
  }
  </code></pre>
  
  <p>instead of the more straightforward version:</p>
  
  <pre><code>my @array = getInfo();
  
  sub getInfo {
     my @array;
     push @array, "obama";
     # ...
     return @array;
  }
  </code></pre>
  
  <p>The reason, of course, is that I don't want the array to be created locally in the subroutine and then copied on return. </p>
  
  <p>Is that right? Or does Perl optimize that away anyway? </p>