I'm not sure that I do want umask: To clarify, the mode I need the files created with is unknown.
What I'm trying to do is to check the mode of a file that already exists, and then create other files that have the same mode (i.e., I don't know what mode the files need to be created with yet).
So my logic would possibly go something like: 1) get mode of file1;
2) create files file2, file3,..., fileN;
3) chmod files file2,..., fileN to the same mode as file1.
If that makes any more sense... | [reply] [d/l] |
You could do that, sure... in that case you just need to
use stat to get the mode of the file.
my $mode = (stat "foo")[2];
But I think you could use umask, still... and it may make
it easier. Try something like this:
my $mode = (stat "foo")[2];
my $mask = 777 -
join '', (($mode&0700)>>6, ($mode&0070)>>3, ($mode&0007));
umask oct $mask;
I'm not sure if this is absolutely right (please someone
correct me if it isn't), but it seemed to work for the test
cases I tried. | [reply] [d/l] [select] |
Man, I wish I could vote you up twice for this little gem:join '', (($mode&0700)>>6, ($mode&0070)>>3, ($mode&0007));
That's exactly what I was after!
setantae
| [reply] [d/l] |