in reply to Mode of created files

Why not use umask? The only other built-in way I know of that might be of use is perldoc -f -X, but I'm not sure that's what you want. You might look at Stat::lsMode from CPAN if you would rather deal with permissions as -rwxr-xr-x (as ls -l would show you).

Replies are listed 'Best First'.
RE: Re: Mode of created files
by setantae (Scribe) on Mar 28, 2000 at 02:32 UTC
    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...
      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.
        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