title: How do I accept an output parameter array and a scalar in perl?
body: <p>I have a function where I want to check if a path exists, and if it does, add that to an array. Here's what I tried:</p>
  
  <pre><code># If a path exists, adds the canonical version of that path to an array
  sub AddPathCandidate {
      my (@$target, $path) = $_;
      die ('path needed') unless defined($path);
      $path = File::Spec-&gt;canonpath($path);
      if (-e $path) {
          push(@{$target}, $path);
      }
  }
  </code></pre>
  
  <p>where the caller looks like:</p>
  
  <pre><code>my @exampleDirs = ();
  AddPathCandidate(\@exampleDirs, $inDir . 'a');
  AddPathCandidate(\@exampleDirs, $inDir . "../b/a/$arch");
  AddPathCandidate(\@exampleDirs, $inDir . "../../b/a/$arch");
  </code></pre>
  
  <p>But the "die" statement always executes; the second parameter of AddPathCandidate isn't getting through somehow.</p>
  
  <p>Is what I'm trying to do here even possible or is there some more "perl-ish way" to accomplish this?</p>