http://www.perlmonks.org?node_id=140544

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

Fellow Monks,

I am stumped by the behaviour of file functions on a windows NT Server I am using. Basically, I can open a file for reading, but I cannot append to a file. I am using the absolute path in my open statement. I have also tried to use the binmode() function, to no avail. Thus my code looks something like:

$somestuff = "This is a new line for my data file"; $filename = "d:/foo/bar/myfile.dat"; open (DATA,">>$filename") || die("Cannot Open Database File"); binmode (DATA); print DATA $somestuff; close DATA;

This code dies and gives me my "Cannot open database file" error

I also tried to use the path d:\\foo\\bar\\myfile.dat

Does anymonk know what is the problem? Is it a permissions issue? Unfortunately, I am not the administrator of this server!

Thanks Monks...

Replies are listed 'Best First'.
Re: Appending to Files on NT?
by wog (Curate) on Jan 22, 2002 at 04:52 UTC

    You can probably tell what the problem is by including the special variable $! in the error message.

    update: added link

      Excellent idea. In this particular case, the value of $^E might also be helpful. I suspect that the file is open by a program that isn't sharing write access. See the Win32API::File documentation of the $svShare argument to createFile() for more information on this.

              - tye (but my friends call me "Tye")

      Right wog!

      Thanks for the tip! It was a permissions problem. Hmmm... I hope I hope I can set the permissions of the file on the NT server using my linux ftp client!

Re: Appending to Files on NT?
by grep (Monsignor) on Jan 22, 2002 at 04:56 UTC
    I would check your permissions on that file. Else, if this is a CGI application you need to check the permissions of either the IIS anonymous user or the authenticated user.

    HTH

    grep
    grep> cd pub
    grep> more beer
Re: Appending to Files on NT?
by Anonymous Monk on Jan 22, 2002 at 16:13 UTC
    maybe this comes from the the access permissions. try the chmod() function , it gives quite the same results that the DOS-SHELL ATTRIB function. hope this will help...