Reputation: 332
I have a perl script that is refusing to see existing data files. When I take the code and isolate in a test perl script it works fine but in the main perl script it can't find anything.
Code looks like this:
use Cwd qw(cwd);
my $dir = cwd;
print STDERR "gen-decsplecs : dir $dir : file $ARGV[0]\n";
if (-e $ARGV[0]) {
print STDERR "gen-declspecs : File Exists : $ARGV[0]\n";
} else {
print STDERR "gen-declspecs : File does not exist : $ARGV[0]\n";
}
if (-e "C:/Users/walter/Documents/Projects/agar-1.5.0/ada-core/ctxt.h") {
print STDERR "gen-declspecs : File Exists : C:/Users/walter/Documents/Projects/agar-1.5.0/ada-core/ctxt.h\n";
} else {
print STDERR "gen-declspecs : File does not exist : C:/Users/walter/Documents/Projects/agar-1.5.0/ada-core/ctxt.h\n";
}
open(F, $ARGV[0]) || die "$ARGV[0]: $!";
This prints :
gen-decsplecs : dir C:/Users/walter/Documents/Projects/agar-1.5.0 : file './ada-core/ctxt.h'
gen-declspecs : File does not exist : './ada-core/ctxt.h'
gen-declspecs : File Exists : C:/Users/walter/Documents/Projects/agar-1.5.0/ada-core/ctxt.h
'./ada-core/ctxt.h': No such file or directory at mk/gen-declspecs.pl line 93.
gen-declspecs.pl failed
So my question is if the code is executing fomr directory :
C:/Users/walter/Documents/Projects/agar-1.5.0
And is looking for file :
./ada-core/ctxt.h
Why does it not exist on the relative path when the full pathed file :
C:/Users/walter/Documents/Projects/agar-1.5.0/ada-core/ctxt.h
does exist? Especially when I have copied the perl to a test script and it does work!!!
Upvotes: 0
Views: 137
Reputation: 183514
If this line:
print STDERR "gen-declspecs : File does not exist : $ARGV[0]\n";
(which doesn't include single-quotes) is printing this output:
gen-declspecs : File does not exist : './ada-core/ctxt.h'
(which does), then that means your $ARGV[0]
starts and ends with spurious single-quotes. -e
isn't going to strip those out; for all it knows, maybe you really are interested in a folder named '.
that contains a folder named ada-core
that contains a file named ctxt.h'
!
To fix this, you need to run your script correctly; don't put spurious single-quotes in the arguments to it.
(If you're coming from a Unix-like environment, you need to be aware that the default Windows shell does not use the same quoting rules at all.)
Upvotes: 1