XeneX has asked for the wisdom of the Perl Monks concerning the following question:

I recently set me up the server with a local provider running their digs on a Windows 2000 system and I find I can't open files in Perl.... i.e. the following code...
open (FILE, "quotes.txt") || die "Could not open file! $!"; @LINES = <FILE>; close (FILE);
...dies with "Could not open file! No such file or directory at blah blah blah" even though the file does certainly exist. I've tried opening different files in different directories but nothing will go. My guess is it's because of file permissions, but because I'm doing this remotely over FTP, I can't fuss with the file permissions once they're on their server. FTPing a CHMOD doesn't do anything in this case, n'est pas? Well, whether it is supposed to or not, it's not working. Could it be something other than permissions? Any idears or suggestions, wise ones? I thought I would ask here before shouting and waving my fists at the admins of the server just in case I'm missing something. Danke. X

Replies are listed 'Best First'.
Re: Files on a Win2000 server
by dws (Chancellor) on Feb 24, 2002 at 00:20 UTC
    A common problem in situations where you don't have shell access, and have to upload CGI scripts and data files via FTP, is that things aren't where you think they are when the script executes.

    One brute-force way of determining what is there is to upload a test CGI that does

    use Cwd; print "Content-type: text/plain\n\n"; print getcwd(), "\n\n"; opendir(DIR, ".") or die ".: $!"; print join("\n", readdir(DIR)), "\n"; closedir(DIR);
    The will tell you where the script thinks it is when executing, and what else is there. You may find that you need to either chdir() or use an absolute path to open data files that reside elsewhere.

      Thank you! Apparantly the working directory was C:/WINNT instead of my location on the server. I always thought the wd was the directory where the script is being executed unless changed in the script. Guess not. Thanks for the useful bit of code, dws. A specific chdir() has healed all wounds.
      X
Re: Files on a Win2000 server
by beebware (Pilgrim) on Feb 24, 2002 at 20:30 UTC
    To me, the 'No such file' message would indicate that there is no such file and there is no problem with the file permissions. However the 'No such file or directory at blah blah blah' message should help. Check that blah blah blah is actually the path that your file is meant to be in - if it isn't, then the problem is obvious. It may be an idea to put the absolute filepath in your script just for safety anyway.