bjhobbs has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: can't open file from another machine
by Corion (Patriarch) on Jun 29, 2005 at 18:21 UTC | |
|
Re: can't open file from another machine
by brian_d_foy (Abbot) on Jun 29, 2005 at 17:47 UTC | |
by ikegami (Patriarch) on Jun 29, 2005 at 18:35 UTC | |
by brian_d_foy (Abbot) on Jun 30, 2005 at 06:56 UTC | |
|
Re: can't open file from another machine
by bofh_of_oz (Hermit) on Jun 29, 2005 at 18:04 UTC |