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

If I mkdir I can set the permissions for the directory I create:
mkdir "new_directory", 0777 or die "Can't mkdir the directory: $!";
Anyone know a simple way to set the permissions as I would like them set when I save a file:
open MUGSHOTWRITE, "> mugshot.jpg" or die "can't write to mugshot.jpg + $!"; binmode MUGSHOTWRITE; print MUGSHOTWRITE @mugshot;
or is chown the only way after the fact?
Thanks for any help on this

"No matter where you go, there you are." Jeff Pflueger - Struggling Perl knowledge sponge

Replies are listed 'Best First'.
Re: permissions, open and chown
by Fletch (Bishop) on Apr 03, 2002 at 21:53 UTC

    ITYM `chmod' not `chown'. And open creates files with a mode of 0666 which gets xor'd against the current process' umask (as perldoc -f open explains).

    Update: As a clarification, the umask is bitwise xor'd with 0666, so if your process currently has a umask of 022 (a sane, common value) would result in permissions of 0644 on the file.

Re: permissions, open and chown
by Zaxo (Archbishop) on Apr 03, 2002 at 22:11 UTC

    sysopen FILEHANDLE, FILENAME, MODE, MASK

    The resulting handle is just as good as one from open.

    After Compline,
    Zaxo

Re: permissions, open and chown
by RMGir (Prior) on Apr 03, 2002 at 22:44 UTC
    You can set your umask using umask.

    For example, if you want 0666, use umask 0 (or 0111). For 0655, use umask 022.

    At least on Linux, this won't create files with +x set. But that may be platform dependent.
    --
    Mike

    (Edit: Added note about +x not getting set, after actually testing my code :))