Reputation: 6592
I have this directory structure:
$ ls -F
analyze/
data.pl
input.pl
logminer.txt
logSearch.pl
readFormat.pl
Version Notes.txt
datadump.pl
format/
logminer.pl
logs/
properties.txt
unzip.exe
I run:
perl -e 'if (!(-d analyze)){ print "poo\n"}'
and it prints poo
.
What is missing here? I have done tests like this earlier and it would correctly identify that the directory exists. Why not this directory?
Upvotes: 1
Views: 77
Reputation: 385657
First,
-d analyze
means "check if the file handle anaylyze
is a directory handle". You want
-d 'analyze'
Now, you say you still get the problem by doing that, so check what error you're getting.
my $rv = -d 'analyze';
die "stat: $!" if !defined($rv);
die "Not a dir" if !$rv;
-d
is just a thin wrapper around stat(2)
, so it's not Perl that "can't see", it's the system.
The most common errors:
Upvotes: 2
Reputation: 360632
perl -e 'if (!(-d "analyze")){ print "poo\n"}'
^-- ^---
missing quotes?
edit: changed to double quotes - forgot this was for command-line perl
Upvotes: 5