According to the documentation of the "stat" function we can use Fcntl::S_IFMT($mode) call, where $mode is $stat2.
Results of the Fcntl::S_IFMT($mode) can be bit-anded with the various constants (S_IFREG, S_IFDIR, S_IFLNK, S_IFBLK, S_IFCHR, S_IFIFO, S_IFSOCK, S_IFWHT, S_ENFMT) to determine file type.
So, my question is - why last test returns TRUE?
'/etc/passwd' - is a regular file (not a link), and first two tests confirms this.
But last test says, that '/etc/passwd' is a link.
#!/usr/bin/env perl use strict; use warnings; use Fcntl qw[]; my $path = '/etc/passwd'; my @stat = stat $path or die $!; printf "%s\n", -l $path ? 1 : 0; # 0 - OK, not a link printf "%s\n", Fcntl::S_ISLNK( $stat[2] ) ? 1 : 0; # 0 - OK, not a +link printf "%s\n", Fcntl::S_IFMT( $stat[2] ) & Fcntl::S_IFLNK ? 1 : 0; +# 1 - ERROR __END__
In reply to Unexpected Fcntl::S_IFLNK behavior by zdm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |