-e fails sometimes

A

Asterbing

Hello. Under ActivePerl/Apache2/Win2k, sometimes (not everytime) the
file existence test fails while the path is correct.

For example, here sometimes $fileok becomes zéro, while $file exist on
disk in fact.

if (! -e $file){$fileok = 0;}

Is-it a -e stability issue ?
Does the $file syntax should follow some rules (comes from a form and I
don't escape the "\", is that ok ?) ?

Should I go through open rather than -e ?

What do you think about that ?
 
P

Paul Lalli

Asterbing said:
Hello. Under ActivePerl/Apache2/Win2k, sometimes (not everytime) the
file existence test fails while the path is correct.

For example, here sometimes $fileok becomes zéro, while $file exist on
disk in fact.

if (! -e $file){$fileok = 0;}

Is-it a -e stability issue ?

No, it's a "your code is wrong" issue. But you haven't shown us any
code, so we don't know what's wrong with it.
Does the $file syntax should follow some rules (comes from a form and I
don't escape the "\", is that ok ?) ?

What \ are you talking about? Please post a short-but-complete script
that demonstrates the error you're having.
Should I go through open rather than -e ?

No, since they do very different things.
What do you think about that ?

I think you should read and follow the Posting Guidelines for this
group.

Paul Lalli
 
A

Asterbing

Please post a short-but-complete script
that demonstrates the error you're having.

This code, on some stations, on a LAN under Win32, sometimes, display
"C:\TEST\stats\histo.gif not found" even if the file exists on disk in
this path.

#!/usr/bin/perl
use strict;
print "Content-type: text/html\n\n";
my $file = "C:\\TEST\\stats\\histo.gif";
if (! -e $file){ print $file." not found"; }
else { print $file." found"; }
exit 0;
 
J

John Bokma

Paul Lalli said:
....


What \ are you talking about?

Think! Win2K -> \

We expect people posting a message to have some clue, why not the people
who reply?
 
P

Paul Lalli

John said:
Think! Win2K -> \

We expect people posting a message to have some clue, why not the people
who reply?

Are you honestly going to tell me that with the post the OP presented
us, we should assume the only \ he had in his string were correct Win2k
directory separators?

I for one chose not to. And the OP posted no code to make me believe
otherwise.

Paul Lalli
 
J

John Bokma

Paul Lalli said:
Are you honestly going to tell me that with the post the OP presented
us, we should assume the only \ he had in his string were correct
Win2k directory separators?

Yup, but maybe I am good in reading between the lines. I have to, since
it's what I have been doing for 12+ years when I talk with my customers. I
mean, if you think "newbies" posting here can be unclear...
I for one chose not to. And the OP posted no code to make me believe
otherwise.

I think he just did, and again I am right :-D.
 
A

A. Sinan Unur

This code, on some stations, on a LAN under Win32, sometimes, display
"C:\TEST\stats\histo.gif not found" even if the file exists on disk in
this path.

#!/usr/bin/perl
use strict;
print "Content-type: text/html\n\n";
my $file = "C:\\TEST\\stats\\histo.gif";

my $file = 'C:/TEST/stats/histo.gif';
if (! -e $file){ print $file." not found"; }
else { print $file." found"; }
exit 0;

This is probably a permissions issue.

Sinan
--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
 
J

John Bokma

A. Sinan Unur said:
my $file = 'C:/TEST/stats/histo.gif';

Which is just a different notation (which is easier to type), and not
going to change anything (you know it, I know it, does the OP know it?)
 
X

xhoster

Asterbing said:
This code, on some stations, on a LAN under Win32, sometimes, display
"C:\TEST\stats\histo.gif not found" even if the file exists on disk in
this path.

#!/usr/bin/perl
use strict;
print "Content-type: text/html\n\n";
my $file = "C:\\TEST\\stats\\histo.gif";
if (! -e $file){ print $file." not found"; }

Print the error message, it might be helpful:

if (! -e $file){ print $file." not found: $!"; }
else { print $file." found"; }
exit 0;

What do you mean by sometimes? If you put this in a loop and executed it
100000 times on the exact same $file, while nothing else is touching that
file, would it sometimes fail and sometimes succeed? Or does the sometimes
that it fails have a different $file than the sometimes that it succeeds?

Are files being added and removed while all of this going on? If so, how
do you know that the file did in fact exist on disk at the exact instance
that -f was executed?

Xho
 
B

Bart Van der Donck

John said:
Which is just a different notation (which is easier to type), and not
going to change anything

Though there's no immediate danger, you could encounter situations like
this:

#!/usr/bin/perl
my $file = "C:\\TEST\\stats\\histo.gif";
my $twofiles =
"C:\\TEST\\stats\\histo.gif C:\\TEST\\stats\\resto.gif";
$twofiles =~s/$file/moved_to_other_location/g;
print $twofiles;

I think / and ' are better practice than \\ and ".
 
A

Asterbing

This is probably a permissions issue.

On Win2k station with browser, I'm logged as admin. So with all
read/write/exec rights. However, I'm tried to display and delete the
given file outside of the Perl script and it succeeds. Strange !
 
T

Tad McClellan

Asterbing said:
OK, adopted. Is that true for others strings than the path ones ?
^^^^

There are several parts to your "that".

It is true that single quotes are "better practice" that double
quotes, unless you _need_ one of the two extra things that double
quotes give you (backslash escapes and interpolation). This
applies to all string literals.

It is true that minimizing the rampant use of backslashing
is a better practice. This applies to many places but primarily
to string literals and regular expressions. Using one of
Perl's alternate forms of quoting can help with this one.

It is not true that you can use slash instead of backslash
in other strings, as that kinda depends on what the strings
are going to be used for.
 
J

John Bokma

Asterbing said:
On Win2k station with browser, I'm logged as admin. So with all
read/write/exec rights. However, I'm tried to display and delete the
given file outside of the Perl script and it succeeds. Strange !

Perl script runs as IUSR_computername (with computername the name of your
computer), you run as admin...
 
A

Asterbing

Problem is gone this monday without any change this week-end : I don't
understand why and it's very worring to be in an unstable state like
this. Well, here s the script which didn't worked friday and works well
today. Why ? Don't know !

use strict;
print "Content-type: text/html\n\n";
my $file = 'C:/TEST/stats/histo.gif';
if (! -e $file){ print $file." not found : $!"; }
else { print $file." found"; }
exit 0;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top