Perlfunc: get_file_perm()

Quick function to get the permissions of a file with Perl.

sub get_file_perm {
    my $file = shift();

    # Permissions are the second element of stat
    my $mode = (stat($file))[2];
    my $perm = sprintf("%04o",$mode & 07777);

    return $perm;
}
Leave A Reply
All content licensed under the Creative Commons License