in reply to How to determine a file's type via stat()

This is actually documented in the docs for stat. Basically, you import the S_IF* functions from the Fcntl module:
use Fcntl ':mode'; print "It's a directory!" if S_IFDIR( (stat($file))[2]);
For a different way of doing this, have a look at the file test operators in perlfunc.

CU
Robartes-

Replies are listed 'Best First'.
Re: Re: How to determine a file's type via stat()
by draconis (Scribe) on May 09, 2003 at 17:24 UTC
    Thanks, but that is not exactly what I was looking for. I know I can use the file-test operators. What I would like to know if if the first bit of the octal returned by stat for mode will reveal what it really is. So, for instance, if the first bit is a 2 then that means "X".

    I was trying to avoid using the file-test operators if at all possible. If it is not possible then I will proceed with such.

    Any further thoughts?

      I know I can use the file-test operators. What I would like to know if if the first bit of the octal returned by stat for mode will reveal what it really is. So, for instance, if the first bit is a 2 then that means "X".

      Actually, that's what the S_IF* functions do for you. If you want to do this yourself, have a look at the bitshift operators (<< and >>) to do bitwise arithmetic.

      CU
      Robartes-

      draconis,
      robartes has pointed you in the right direction. Read the docs on stat.

      You can import symbolic mode constants (S_IF*) and functions (S_IS*) from the Fcntl module:
      S_IFREG S_IFDIR S_IFLNK S_IFBLK S_ISCHR S_IFIFO S_IFSOCK S_IFWHT S_ENFMT

      Figure the bitwise math out and create a hash lookup.

      Cheers - L~R