File type is better detected using the file test operators. You can pass them the special name _ to reuse the results of the previous stat/lstat/file test. Also see the filetest pragma for information on handling ACLs.
use strict; use warnings; my $file = $ARGV[0]; my $mode = (lstat($file))[2]; print "File: $file\n"; print "mode = $mode\n"; printf "mode (octal) = %o\n", $mode; printf "Permissions = %04o\n", $mode & 07777; -r _ && print "File is readable by effective uid/gid.\n"; -w _ && print "File is writable by effective uid/gid.\n"; -x _ && print "File is executable by effective uid/gid.\n"; -o _ && print "File is owned by effective uid.\n"; -R _ && print "File is readable by real uid/gid.\n"; -W _ && print "File is writable by real uid/gid.\n"; -X _ && print "File is executable by real uid/gid.\n"; -O _ && print "File is owned by real uid.\n"; -e _ && print "File exists.\n"; -z _ && print "File has zero size (is empty).\n"; -s _ && printf "File has size: %d.\n", -s _; -f _ && print "File is a plain file.\n"; -d _ && print "File is a directory.\n"; -l _ && print "File is a symbolic link.\n"; -p _ && print "File is a named pipe (FIFO).\n"; -S _ && print "File is a socket.\n"; -b _ && print "File is a block special file.\n"; -c _ && print "File is a character special file.\n"; print "=============================\n";

In reply to Re: Extract file type from stat() mode by ysth
in thread Extract file type from stat() mode by joe_s

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.