Dear Folks,
I have encountered inconsistent behaviour with the file test (-X) operators. I
am using perl, v5.8.8 built for i486-linux-gnu-thread-multi on a Kubuntu Feisty
system.
I show below my minimal test file:
----------- Minimal Test File -----------
#!/usr/bin/perl -w
use diagnostics;
# Minimal example for problem with file test, or -X, operators
$testdir = "/usr";
opendir(DH, $testdir) or die "Could not open $testdir: $!\n";
while (defined($file = readdir(DH)))
{
if (-d $file)
{
print "$file is a directory\n";
}
elsif (-f $file)
{
print "$file is a regular file\n";
}
else
{
print "$file is neither a directory nor a regular file\n";
}
}
closedir(DH);
-----------------------------------------
The results I get are:
-----------------------------------------
include is a directory
src is a directory
lib is a directory
sbin is neither a directory nor a regular file
bin is a directory
local is neither a directory nor a regular file
lib32 is neither a directory nor a regular file
games is neither a directory nor a regular file
share is neither a directory nor a regular file
. is a directory
.. is a directory
lib64 is neither a directory nor a regular file
X11R6 is neither a directory nor a regular file
-----------------------------------------
and
ls -al /usr
gives:
-----------------------------------------
drwxr-xr-x 13 root root 4096 2007-05-15 16:18 .
drwxr-xr-x 23 root root 4096 2007-05-15 00:55 ..
drwxr-xr-x 2 root root 69632 2007-05-17 00:12 bin
drwxr-xr-x 2 root root 4096 2007-05-15 08:45 games
drwxr-xr-x 35 root root 4096 2007-05-15 16:10 include
drwxr-xr-x 149 root root 69632 2007-05-16 14:33 lib
drwxr-xr-x 3 root root 4096 2007-05-15 01:33 lib32
drwxr-xr-x 3 root root 4096 2007-05-15 16:18 lib64
drwxr-xr-x 10 root root 4096 2007-04-17 13:19 local
drwxr-xr-x 2 root root 12288 2007-05-17 00:12 sbin
drwxr-xr-x 244 root root 12288 2007-05-16 13:55 share
drwxrwsr-x 4 root src 4096 2007-04-17 13:23 src
drwxr-xr-x 3 root root 4096 2007-04-17 13:21 X11R6
-----------------------------------------
Can anyone please tell me why I get this inconsistent behaviour and how to
overcome it?
I have read of the possibility of a race condition with these operators but I am
unsure whether it applies here.
Thank you.
Chandra
17 May 07
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/