in reply to permissions

I tried using File::stat (which would be another way to do this) but I couldn't grasp what it was doing..

It suggests something like:

use File::stat; $st = stat($file) or die "No $file: $!"; if ( ($st->mode & 0111) && $st->nlink > 1) ) { print "$file is executable with lotsa links\n"; }

My problem was the 0111 and how I could tell if the file was writeable even if it were a readable and executable by group/user/world.. those are different numbers. I guess I would have to know and test against these numbers..

Does anyone have any insight on that? In the interim, there is this oogly thing..

my @listfiles=`ls -l ./`; foreach(@listfiles) { chomp; $_=~s/ /\t/g; my @details = split(/\t/, $_); print "$details[-1]: $details[0]\n"; }

it works, but then, it's just a ls -l of the contents of the dir. whoo.

Replies are listed 'Best First'.
Re: Re: permissions
by blakem (Monsignor) on Jul 14, 2001 at 01:51 UTC
    Just use the regular stat function.

    From perldoc -f stat

    -----------------------------
    Because the mode contains both the file type and its permissions, you should mask off the file type portion and (s)printf using a C<"%o"> if you want to see the real permissions.

    $mode = (stat($filename))[2]; printf "Permissions are %04o\n", $mode & 07777;
    -----------------------------

    -Blake

      Excellent! that did just what I wanted. Thanks!

      Why is it that I everything I do in perl must be so long? heh.