title: perl error: Use of uninitialized value $_ in concatenation (.) or string
body: <p>I get the following error:</p>
  
  <pre><code>Use of uninitialized value $_ in concatenation (.) or string at checkfornewfiles.pl line 34.
  </code></pre>
  
  <p>when attempting to run the following code :</p>
  
  <pre><code>#!/usr/bin/perl -w
  #Author: mimo
  #Date 3/2015
  #Purpose: monitor directory for new files...
  
  AscertainStatus();
          ######### start of subroutine ########
  sub AscertainStatus {
      my $DIR= "test2";
  
      ####### open handler #############
      opendir (HAN1, "$DIR") || die "Problem: $!";
  
      ########## assign theoutput of HAN1 to array1 ##########
      my @array1= readdir(HAN1);
  
      ######## adding some logic #########
  
      if ("$#array1" &gt; 1) {   #### if files exists (more than 1) in the directory #######
              for (my $i=0; $i&lt;2; $i++) {shift @array1;}      ####### for i in position 0 (which is the . position) loop twice and add one (the position ..) get rid of them #######
              MailNewFiles(@array1);
      }       else { print "No New Files\n";}
  
  }
  
  sub MailNewFiles {
      $mail= "sendmail";
  
      open ($mail, "| /usr/lib/sendmail -oi -t" ) ||die "errors with sendmail $!"; # open handler and pipe it to sendmail
      print $mail &lt;&lt;"EOF";    #print till the end of fiEOF
      From: "user";
      To: "root";
      Subject: "New Files Found";
  
      foreach (@_) {print $mail "new file found:\n $_\n";}
  EOF
      close($mail);
  }
  
  #End
  </code></pre>
  
  <p>I am new to perl and I don't know what's going wrong. Can anyone help me ?</p>