Re: Checking to see if file exists.
- From: jwkrahn@xxxxxxx (John W. Krahn)
- Date: Wed, 30 Jul 2008 12:23:44 -0700
tvadnais wrote:
I am totally confounded by what appears to be a bug in the "does file exist"
functionality.
Here is the code as it stands now:
my $tmpfile = substr ($file, 0, index($file, ".pgp"));
I would probably do that like this instead:
( my $tmpfile = $file ) =~ s/\.pgp\z//;
print cwd(); ## debug code: to make sure we're in the correct
directory
chomp($tmpfile); ## debug code: Added this to see if there was any thing
funny in the file name.
There is no need to chomp() the $tmpfile variable.
if (-e $tmpfile) {
# if (-e "$tmpfile"){ ##This doesn't work
# if (-e "F0715PAY.TXT") { ## This does work, but it needs to be a
variable
## Do magic stuff to file. } else {
## Send error message
}
I stepped through the code with the debugger for the above snippet and this
is what I got (with a few minor edits for clarity sake)
The following files were found in directory: F0715PAY.TXT.pgp,
J0715PAY.TXT.pgp, C0715PAY.TXT.pgp
So you don't actually have a file named 'F0715PAY.TXT' in this directory? You say that
-e "F0715PAY.TXT"
works, then
$tmpfile = "F0715PAY.TXT";
-e $tmpfile
should work exactly the same.
main::(rmain.pl2): my $tmpfile = substr ($file, 0, index($file, ".pgp"));
DB<> n
DB<> x $tmpfile
0 'F0715PAY.TXT.pgp'
DB<> /xfer/test/RDY
main::(rmain.pl2): chomp($tmpfile);
DB<> n
main::(rmain.pl2): if (-e $tmpfile) {
DB<> x $tmpfile
0 'F0715PAY.TXT'
DB<> n
main::(rmain.pl2): LogMsg (MSG => "Couldn't find $F0715PAY.TXT", Echo =>
$debug);
That string passed to LogMsg looks suspicious. What is in the variable $F0715PAY? Do you have the warnings and strict pragmas enabled?
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
.
- References:
- Checking to see if file exists.
- From: Tvadnais
- Checking to see if file exists.
- Prev by Date: RE: use of Configuration files
- Next by Date: Re: reading a few bytes into a file
- Previous by thread: RE: Checking to see if file exists.
- Next by thread: Re: beginners Digest 29 Jul 2008 21:32:20 -0000 Issue 3524
- Index(es):