title: How would I search through a directory and all subdirectories recursively using perl
body: <p>I saw <a href="https://stackoverflow.com/questions/1370067/how-do-i-check-for-a-sub-subdirectory-in-perl/1370512#1370512">this link</a> using glob</p>
  
  <p>It's not quite what I want to do though.</p>
  
  <p>Here is my plan. In order to search though a directory for any files that partially match a string, given to my function as a parameter, say <code>/home/username/sampledata</code> and the string, say <code>data</code>.</p>
  
  <p>I give the option for the user to include a flag at execution enforcing whether or not to check subdirectories, and currently by default the script does not include subdirectories.</p>
  
  <p>The pseudocode for the one that does include the subdirectories would look like this.</p>
  
  <p>The array that I am saving the file paths to is global</p>
  
  <pre><code>  @fpaths;
  
    foo($dir);
  
    sub foo{
        get a tmp array of all files
  
        for ($i=0 ; $i&lt;@tmp ; $i++) {
            next if ( $tmp[$i]is a hidden file and !$hidden) ; #hidden is a flag too
  
            if($tmp[$i] is file) {
                 push (@fpaths, $dir.$tmp[$i]);
            }
            if($tmp[$i] is dir) {
                 foo($dir.$tmp[$i]);
            }
  
         }
     }
  </code></pre>
  
  <p>That looks pretty solid.</p>
  
  <p>What I'm hoping to achieve is an array of every file with the full path name saved.</p>
  
  <p>The part I do not know how to do is get the list of every file. Hopefully this can be done with glob.</p>
  
  <p>I have been able to use <code>opendir</code>/<code>readdir</code> to read every file and I could do this again if I knew how to check if the result is a file or a directory. </p>
  
  <p>So my questions are:</p>
  
  <ol>
  <li><p>How to use <code>glob</code> with a path name to get an array of every file/sub directory</p></li>
  <li><p>How to check if an item on the formerly found array is a directory or a file</p></li>
  </ol>
  
  <p>Thanks everybody</p>