title: Perl: trying to put ls -l into an array goes haywire
body: <p>I'm starting with this simple code, which goes through /home/ and determines whether an object is a file or a directory</p>
  
  <pre><code>#!/usr/bin/perl
  
  
  # My Starting directory.  I could also read this from the command line
  $start = "/home/";
  $count = 0; # How many non-file objects found.  Line un-necessary
  
  # Initialize the list
  push (@dirs, $start);
  
  # Iterate through the list (really a queue) 
  # We could also do this with a shift, but this works
  foreach $curr (@dirs)
      {
      # Get the directory listing for the current directory
      # Note that -F appends a character for the type of object it is
      # on the end (/) for directory.
  
  
      my @lines = split /\n/, `ls -F $curr`;
  
      # Iterate through the things we got from the ls
      foreach $line (@lines)
      {
          # The chomp is not necessary because the split strips out
          # the seperator characters.
          #chomp $line;
  
          # If it ends in a / it's a directory. add it to the end of
          # the list
          if ($line =~ m#/$#)
          {
              print "Directory of -&gt; " . $curr.$line . "\n";
              push(@dirs, ($curr.$line));
          }
          else
          {
              print "File of ==&gt; " . $curr.$line . "\n";
              $count++;
          }
      }
  }
  
  # Silly print statement
  print "I found " . $count . " non-directory objects.\n";
  </code></pre>
  
  <p>And I tried modifying it to use <strong>ls -l</strong> since the rest of the program depends on the info from it, but that's where things go weird.</p>
  
  <p>What I modified: </p>
  
  <pre><code>my @lines = `ls -l $curr`;
  
  if ($line =~ m#-.........#)
  
  elsif ($line =~ m#d.........#)
  </code></pre>
  
  <p>I don't mean to keep the regex that way, I was going to do it the right way once I got it to actually proceed correctly.</p>
  
  <p>And I added a stupid debug, right after the foreach</p>
  
  <pre><code>print("$line \n");
  </code></pre>
  
  <p>What I should get is kind of like this:</p>
  
  <pre><code>File of ==&gt; /home/paul/perl/spider*
  Directory of -&gt; /home/paul/perl/test/
  I found 9 non-directory objects.
  </code></pre>
  
  <p>Instead, I get this:</p>
  
  <pre><code>total 8
  
  drwxr-xr-x 28 paul paul 4096 2014-03-11 01:31 paul
  
  Directory of -&gt; /home/drwxr-xr-x 28 paul paul 4096 2014-03-11 01:31 paul
  
  drwxr-xr-x  2 test test 4096 2014-03-10 02:12 test
  
  Directory of -&gt; /home/drwxr-xr-x  2 test test 4096 2014-03-10 02:12 test
  
  ls: cannot access /home/drwxr-xr-x: No such file or directory
  ls: cannot access 28: No such file or directory
  ls: cannot access paul: No such file or directory
  ls: cannot access paul: No such file or directory
  ls: cannot access 4096: No such file or directory
  ls: cannot access 2014-03-11: No such file or directory
  ls: cannot access 01:31: No such file or directory
  ls: cannot access paul: No such file or directory
  ls: cannot access /home/drwxr-xr-x: No such file or directory
  ls: cannot access 2: No such file or directory
  ls: cannot access 4096: No such file or directory
  ls: cannot access 2014-03-10: No such file or directory
  ls: cannot access 02:12: No such file or directory
  test:
  
  total 0
  
  
  
  test:
  
  total 0
  
  
  
  test:
  
  total 0
  
  I found 0 non-directory objects.
  </code></pre>
  
  <p>I'm at wit's end and don't understand why everything else I've tried has failed as well.  Thanks in advance!</p>