title: Missing error in $@ for Perl Net::FTP
body: <p>After figuring out (via SO, of course) that the error for a bad <code>$ftp = Net::FTP-&gt;new()</code> call is in <code>$@</code> while subsequent errors can be obtained by <code>$ftp-&gt;message()</code>, I'm striking a small problem.</p>
  
  <p>My code is basically:</p>
  
  <pre><code>while (1) {
      # Wait for cycle start, then get file list into @filelist.
  
      foreach $file (@filelist) {
          my $ftp = Net::FTP-&gt;new ($host);
          if (! $ftp) {
              logError ("Could not connect to host [$host]: $@");
              return;
          }
          # More FTP stuff below with $ftp-&gt;message() error checking.
          $ftp-&gt;quit();
      }
  }
  </code></pre>
  
  <blockquote>
    <p>Aside: yes, I know I can probably do this in one FTP session, but there are good reasons for leaving it in separate sessions at the moment.</p>
  </blockquote>
  
  <p>Now this is being called in a loop, once per file, all going to the same host, but I'm getting a slightly different behaviour on the first attempt in most cycles. The script is a long-running one, with each cycle starting on the hour and half hour so it's not some issue with the first ever attempt after program start, since it happens on cycles other than the first as well.</p>
  
  <p>Now I <em>know</em> that these connections should fail, simply because the machines I'm trying to access are not available on my development network.</p>
  
  <p>The trouble is that the errors coming out in the log file are:</p>
  
  <pre><code>E 2012-02-05 18:00:13 Could not connect to host [example.com]: 
  E 2012-02-05 18:00:13 Could not connect to host [example.com]:
      Net::FTP: connect: Connection refused
  E 2012-02-05 18:00:14 Could not connect to host [example.com]:
      Net::FTP: connect: Connection refused
  </code></pre>
  
  <p>As you can see, the <code>$@</code> variable seems to be not populated the first file of the cycle. I've edited this question slightly since I've just noticed the latest cycle had all three lines with the error message. Going back over the logs with the command:</p>
  
  <pre><code>grep refused logfile | awk '{print substr($3,1,5)}' | uniq -c
  </code></pre>
  
  <p>to get the dates and counts, turns up the following statistics:</p>
  
  <pre><code>  3 11:00
    3 11:30
    3 12:00
    3 12:30
    3 13:00
    3 13:30
    2 14:00
    3 14:30
    3 15:00
    3 15:30
    3 16:00
    2 16:30
    2 17:00
    2 17:30
    2 18:00
    2 18:30
    2 19:00
    3 19:30
  </code></pre>
  
  <p>indicating that some have the correct count of error messages but not all.</p>
  
  <p>I'm wondering if anyone knows why this may be the case.</p>