I have a script which writes text files like this.
open (FILEHANDLE, ">>$filepath")¦¦&ErrorMessage;
print FILEHANDLE "$pageoutput";
close FILEHANDLE;
This prints a string that I've stuffed into $pageoutput.
What I need to know is how can I set the permissions I need at the same time.
Can anyone help?
Best wishes
Sid
Perl has a chmod function:
chmod 0755, @files;
There are some caveats, ie the mode should be an octal number (use that leading zero), and not a string:
[rocketaware.com...]
Sean
I asked the same question on Perlmonks and got this suggestion which is what I think I will use.
my $umask = umask 0;
open (FILEHANDLE, ">>$filepath")¦¦&ErrorMessage;
umask $umask;
print FILEHANDLE "$pageoutput";
close FILEHANDLE;
I can then adjust permissions by simply changing the value of $umask.
The alternative is apparently to use sysopen which has switches for various attributes including what to do if the file can't be found and permissions.
Best wishes
Sid
There's a good explanation of how to use the mask here. [perldoc.com ]
In effect the umask numbers are simply subtracted from the existing permissions. I think that i may get into the habit of using sysopen to create my files with a creation mode of 0666 and then use the mask to tweak these to suit my requirements.
I must confess that until recently non of my CGIs created files on the server they just sent HTML to the browser and emails to me. Reading and writing files opens up a whole new world of possibilities (and dangers!). As a consequence of not creating files in the past and having access to some excellent GUI FTP clients and permissions utilities I had never had to know that RWX = 7 I just selected the relevant check boxes and submitted.
Thanks for everyones help on this.
Best wishes
Sid