-e fails sometimes

Discussion in 'Perl Misc' started by Asterbing, Mar 31, 2006.

  1. Asterbing

    Asterbing Guest

    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 ?
    Asterbing, Mar 31, 2006
    #1
    1. Advertising

  2. Asterbing

    Paul Lalli Guest

    Asterbing wrote:
    > 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
    Paul Lalli, Mar 31, 2006
    #2
    1. Advertising

  3. Asterbing

    Asterbing Guest

    In article <>,
    says...
    > 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;
    Asterbing, Mar 31, 2006
    #3
  4. Asterbing

    John Bokma Guest

    "Paul Lalli" <> wrote:

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


    ....

    >> 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?


    Think! Win2K -> \

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


    --
    John Bokma Freelance software developer
    &
    Experienced Perl programmer: http://castleamber.com/
    John Bokma, Mar 31, 2006
    #4
  5. Asterbing

    Paul Lalli Guest

    John Bokma wrote:
    > "Paul Lalli" <> wrote:
    >
    > > Asterbing wrote:
    > >> Hello. Under ActivePerl/Apache2/Win2k, sometimes (not everytime) the
    > >> file existence test fails while the path is correct.


    > >> 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?

    >
    > 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
    Paul Lalli, Mar 31, 2006
    #5
  6. Asterbing

    John Bokma Guest

    "Paul Lalli" <> wrote:

    > John Bokma wrote:
    >> "Paul Lalli" <> wrote:
    >>
    >> > Asterbing wrote:
    >> >> Hello. Under ActivePerl/Apache2/Win2k, sometimes (not everytime)
    >> >> the file existence test fails while the path is correct.

    >
    >> >> 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?

    >>
    >> 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?


    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.

    --
    John Bokma Freelance software developer
    &
    Experienced Perl programmer: http://castleamber.com/
    John Bokma, Mar 31, 2006
    #6
  7. Asterbing <> wrote in
    news::

    > In article <>,
    > says...
    >> 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";


    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 <>
    (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
    A. Sinan Unur, Mar 31, 2006
    #7
  8. Asterbing

    Tony Curtis Guest

    >> On Fri, 31 Mar 2006 21:25:50 GMT,
    >> "A. Sinan Unur" <> said:


    > 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.


    and/or ownership and/or a race condition with whatever is
    creating the GIF. Note it's some kind of web environment
    the OP is using.

    hth
    t
    Tony Curtis, Mar 31, 2006
    #8
  9. Asterbing

    John Bokma Guest

    "A. Sinan Unur" <> wrote:

    >> my $file = "C:\\TEST\\stats\\histo.gif";

    >
    > 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?)


    --
    John Bokma Freelance software developer
    &
    Experienced Perl programmer: http://castleamber.com/
    John Bokma, Mar 31, 2006
    #9
  10. Asterbing

    Guest

    Asterbing <> wrote:
    > In article <>,
    > says...
    > > 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"; }


    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

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , Mar 31, 2006
    #10
  11. John Bokma wrote:

    > "A. Sinan Unur" <> wrote:
    >
    > >> my $file = "C:\\TEST\\stats\\histo.gif";

    > >
    > > my $file = 'C:/TEST/stats/histo.gif';

    >
    > 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 ".

    --
    Bart
    Bart Van der Donck, Apr 1, 2006
    #11
  12. Asterbing

    Dr.Ruud Guest

    Bart Van der Donck schreef:

    > $twofiles =~s/$file/moved_to_other_location/g;


    Unless you prepared $file for being used as a regex, you should use \Q.

    --
    Affijn, Ruud

    "Gewoon is een tijger."
    Dr.Ruud, Apr 1, 2006
    #12
  13. Asterbing

    Asterbing Guest

    In article <Xns9797A7455CA92asu1cornelledu@127.0.0.1>,
    d says...
    > 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 !
    Asterbing, Apr 1, 2006
    #13
  14. Asterbing

    Asterbing Guest

    In article <>,
    says...
    > I think / and ' are better practice than \\ and ".
    >


    OK, adopted. Is that true for others strings than the path ones ?
    Asterbing, Apr 1, 2006
    #14
  15. Asterbing <> wrote:
    > In article <>,
    > says...
    >> I think / and ' are better practice than \\ and ".
    >>

    >
    > 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.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Apr 1, 2006
    #15
  16. Asterbing

    John Bokma Guest

    Asterbing <> wrote:

    > In article <Xns9797A7455CA92asu1cornelledu@127.0.0.1>,
    > d says...
    >> 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 !


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

    --
    John Bokma Freelance software developer
    &
    Experienced Perl programmer: http://castleamber.com/
    John Bokma, Apr 1, 2006
    #16
  17. Asterbing

    Asterbing Guest

    In article <>,
    says...
    > There are several parts to your "that".
    >


    Understoof your details. Thanks
    Asterbing, Apr 3, 2006
    #17
  18. Asterbing

    Asterbing Guest

    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;
    Asterbing, Apr 3, 2006
    #18
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Saunders
    Replies:
    0
    Views:
    453
    John Saunders
    Aug 28, 2003
  2. Nehmo Sergheyev
    Replies:
    1
    Views:
    493
    Andrew Urquhart
    May 9, 2004
  3. Marcin Vorbrodt

    ::std sometimes needed, sometimes not

    Marcin Vorbrodt, Sep 16, 2003, in forum: C++
    Replies:
    24
    Views:
    747
    Jerry Coffin
    Sep 17, 2003
  4. Replies:
    1
    Views:
    491
    gkelly
    Nov 29, 2006
  5. Randy Smith
    Replies:
    2
    Views:
    433
    Randy Smith
    Apr 24, 2007
Loading...

Share This Page