Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I need a function that checks if file exists

Seems to me that (on Windows) we can be assured that the specified $file exists if any one of the following three conditions returns true:
-T $file || -B $file defined -T $file defined -B $file
I was also wondering about using -f instead of -e. Are there any files on Windows that will report false for -f ? (If so, then we can't use -f as a test for existence.)

Someone really ought to file a bug report about this because the perldoc -f -X documentation does *not* match the behaviour wrt '-e'.
That documentation implies that -e '""' will return true only if a file named "" exists.
Either the behaviour ought to change to fit the documentation, or the documentation be amended to fit the behaviour.
The documentation also implies that defined -f '""' will return false (but it doesn't).
Here's what I ran as a check:
#!perl -l use warnings; print "-f:"; -f '""' ? print "Returned True (unwanted behaviour)\n" : print "Returned False (wanted behaviour)\n"; print "defined -f:"; defined -f '""' ? print "Returned True (unwanted behaviour)\n" : print "Returned False (wanted behaviour)\n"; print "-T || -B:"; (-T '""' || -B '""') ? print "Returned True (unwanted behaviour)\n" : print "Returned False (wanted behaviour)\n"; print "defined -T:"; defined -T '""' ? print "Returned True (unwanted behaviour)\n" : print "Returned False (wanted behaviour)\n"; print "defined -B:"; defined -B '""' ? print "Returned True (unwanted behaviour)\n" : print "Returned False (wanted behaviour)\n";
And here's the output I got:
-f: Returned False (wanted behaviour) defined -f: Returned True (unwanted behaviour) -T || -B: Returned False (wanted behaviour) defined -T: Returned False (wanted behaviour) defined -B: Returned False (wanted behaviour)
I don't mind filing a bug report about this, but I'll wait for comments about that first (in case I've overlooked something).

Cheers,
Rob

In reply to Re^11: true from (-e "") on Windoze (" is an illegal filename character by syphilis
in thread true from (-e "") on Windoze by CarolinaPerler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (9)
    As of 2014-12-22 23:14 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (133 votes), past polls