I am using ActivePerl for Windows and I am having a problem reading a file from a server (different machine than the script is running on).

Most of the time, the script runs fine, and the files are read without problems. Sometimes, though, my perl script is unable to find the files and I get the following error:"No such file or directory"

The files do exist and I have no trouble accessing them with some C++ code that I have written. I've tried reading the perldoc on the open method but I didn't find anything helpful.

Here's some Perl code that emulates the error:

use strict; open(FILENAMES, "<filenames.txt") or (die "filenames.txt could not be opened: $!\n"); my ($sec, $min, $hour, $day, $month, $year) = localtime(time()); $year += 1900; $month++; while (my $fileInfoString = <FILENAMES>) { chomp $fileInfoString; my @fileInfo = split(/\t/, $fileInfoString); my $filePath = sprintf "%s\\%d\\%02.d\\", $fileInfo[0], $year, $month; unless(open SOURCE_FILE, "<$filePath$fileInfo[1]") { print STDERR "$filePath$fileInfo[1] not opened: $!\n"; next; } print STDERR "$filePath$fileInfo[1] opened.\n"; my $count; while (my $line = <SOURCE_FILE>) { $count++; } print "$count lines.\n"; close SOURCE_FILE; }

filenames.txt contains a list of filepaths (something like \\10.1.101.196\folder\) and filenames (like 023511X.dat).

Can anybody tell me if there is there a problem with the code I have written or could this be an issue with my network speed (I have noticed that sometimes it takes a long time to access the server using other methods)? Does Perl time out if it doesn't get a response fast enough? If so, is there a way to extend the amount of time before it times out?


In reply to can't open file from another machine by bjhobbs

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.