title: Should I manually set Perl's @ARGV so I can use <> to open, scan, and close files?
body: <p>I have recently started learning Perl and one of my latest assignments involves searching a bunch of files for a particular string. The user provides the directory name as an argument and the program searches all the files in that directory for the pattern. Using <code>readdir()</code> I have managed to build an array with all the searchable file names and now need to search each and every file for the pattern, my implementation looks something like this - </p>
  
  <pre><code>sub searchDir($) {
      my $dirN = shift;
      my @dirList = glob("$dirN/*");
      for(@dirList) {
          push @fileList, $_ if -f $_;
  
      }
      @ARGV = @fileList;
      while(&lt;&gt;) {
          ## Search for pattern
      }
  }
  </code></pre>
  
  <p>My question is - is it alright to manually load the @ARGV array as has been done above and use the &lt;> operator to scan in individual lines or should I open / scan / close each file individually? Will it make any difference if this processing exists in a subroutine and not in the main function?</p>