title: Perl - Read multiple files and read line by line of the text file
body: <p>I am trying to read multiple .txt files in a folder. Each file should be read line by line, however, I failed to read multiple .txt files by using glob. Any advice on my code?</p>
  
  <pre><code>my %data;
  @FILES = glob("*.txt");
  
  $EmailMsg .= "EG. Folder(week) = Folder(CW01) --CW01 = Week 1 -- Number is week\n ";
  $EmailMsg .= "=======================================================================================================\n";
  
  # Try to Loop multiple files here
  foreach my $file (@FILES) {
    local $/ = undef;
    open my $fh, '&lt;', $file;
    $data{$file} = &lt;$fh&gt;;
  
    # Read the file one line at a time.
    while (my $line = &lt;$fh&gt;) {
      chomp $line;
      $line =~ s/^\s+//;
      $line =~ s/\s+$//;
      my ($name, $date, $week) = split /\:/, $line;
  
      if ($name eq "NoneFolder") {
        $EmailMsg .= "Folder ($week) - No Folder created on the FTP! Failed to open folder!\n";
      }
  
      if ($name eq "EmptyFiles") {
        $EmailMsg .= "Folder ($week) - No Files insides the folder! Failed download files!\n";
      }
  
    }
  }
  $EmailMsg .= "=======================================================================================================\n";
  $EmailMsg .= "Please note that if you receive this email means that the script is running fine just that no folder is created or no files inside the folder for the week on the FTP.\n";
  
  # close the file.
  #close &lt;$fh&gt;;
  </code></pre>
  
  <p>Currently output:</p>
  
  <pre><code>    EG. Folder(week) = Folder(CW01) --CW01 = Week 1 -- Number is week
    =======================================================================================================
      =======================================================================================================
      Please note that if you receive this email means that the script is running fine just that no folder is created or no files inside the folder for the week on the FTP.
  </code></pre>
  
  <p>It failed to get any .txt files.</p>