traveler has asked for the wisdom of the Perl Monks concerning the following question:

In thinking about this question I thought, "maybe -z returns true for an empty directory -- that might seem like a good idea". Trying it on Windows (Active Perl 5.6.1) it seems that all directories return true for -z! But wait, on Linux (again 5.6.1), all directories return false for -z (presumably because they contain links to . and ..).

Is this behavior documented somewhere? Is it intentional? And, most importantly, is it reasonable?

--traveler

Replies are listed 'Best First'.
Re: -z and directories
by tall_man (Parson) on May 21, 2003 at 16:28 UTC
    Try the following for a directory 'dirname":
    use strict; my $s = (-s 'dirname'); print "s is $s\n";
    On Linux it returns the directory size, 512. On Windows it returns 0. I have cygwin on Windows NT and it shows 0 as the directory size when I say "ls -ld dirname". It must be a difference in file system implementation. The "-z" test simply tells you whether "-s" returns 0 or not, so it's reasonable.