in reply to Extract file type from stat() mode

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";