Perl does not look in your PATH environment variable for files. It looks in the current directory, unless you give it a FULL file path.
| [reply] |
That depends on what the meaning of "is" is. Erm, I mean...
You can do -e '../foo/bar', which checks a file in a different directory, but I don't consider a relative path to be "a FULL file path" either. That's just semantics, I know, but it seemed like something worth clarifying in case the OP reads your comment the way I did.
To the OP: It works like filename arguments (which ignore $PATH), not executable filenames (which search $PATH). ls foo only looks in the current directory, ls /bin/foo only looks in /bin, and ls ../bar/foo only looks in ../bar. -e works the same way.
| [reply] [d/l] [select] |
Of course, you can always use an environment variable to construct the path, if that's what you need:
use strict;
use warnings;
(my $file = shift) or die "No file specified.\n";
my $dir = $ENV{'USER_PATH'} || "."; # Use current directory if USER
+_PATH not set
my $path = "$dir/$file"; # Construct full pathname
s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
| [reply] [d/l] |
| [reply] [d/l] |
I cannot imagine being willing to search the path when checking for a file's existence unless what I really wanted to know was "is another file of the same name somewhere in the path that I wasn't expecting, and that's why it runs so weird?"If I want to know if a particular file exists I always specify where to look, or else use find/dir. Which is likely to turn up instances that could interfere with execution even if NOT in the path per se. | [reply] |
Full path. You can can use $ENV{HOME} to help out, if it is set. Also consider:
- -f "/your/file here", returns true of it is a "file"
- -d "/your/path/to a dir", returns true if node is a dir
| [reply] |