The 'umask' function in your shell is a built-in function. It is executed by the shell itself and changes the setting of the shell itself. If it were a separate executable, then it would run in a sub-process of the shell and would affect itself but not the shell it was invoked from.
If you write a Perl script and run it, it runs in a sub-process of your shell and cannot easily change the settings of your shell.
If you want a Perl script that changes the setting of the shell you invoke it from, you have a challenge. It might be possible, if you have permissions to attach to and control that other process. For example, gdb can attach to a process and modify it in many ways. But I don't think you will find anything in Perl and possibly not in CPAN to do this.
If you want a Perl script that changes the setting for itself and any processes it spawns, that's easy: use the umask function as Corion has suggested.
Here is an example that shows how to invoke the bash 'umask' function from a Perl script, and how to set the umask of the perl script.
use strict;
use warnings;
umask 0037;
system('bash -c umask');
If you run this and you have bash on your system you will see that the umask function in the bash process displays the umask you set in the script. If, after running this script you check the umask of your login shell, from which you invoked the Perl script (I'm making some assumptions here - let me know if they're not valid for you) then you will see that the umask of your login shell is not changed. This is expected. The general rule is that child processes do not change the setting of their parent processes. |