Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^11: true from (-e "") on Windoze (" is an illegal filename character

by syphilis (Chancellor)
on Sep 20, 2012 at 01:58 UTC ( #994574=note: print w/replies, xml ) Need Help??


in reply to Re^10: true from (-e "") on Windoze (" is an illegal filename character
in thread true from (-e "") on Windoze

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994574]
help
Chatterbox?
[atcroft]: (And Feb. is the odd case, because it is 28, unless it is a year divisible by 4, or if it is divisible by both 100 and 400 (at which point it is 29).)
[james28909]: i know but scroll through your calendar on your computer.
[james28909]: i thiught you were going to say make both hands into a fist and puch yourself in the face
[atcroft]: .oO(Sorry, I probably should have said take two normal hands....)
[atcroft]: james28909: No, unless you are a politician, I wouldn't say that (and even if you are, I still probably wouldn't say that).
[james28909]: i mean how hard can it be? its just subtracting days lol
[atcroft]: james28909: What about October 5, 1582?
[stevieb]: atcroft: "Make both hands into fists..."... is something my Ma taught me in our native lang, but I was to ignorant and young to pay attention. Thanks for that :)
[atcroft]: stevieb: Sad to say that I only recently learned that particular trick, but I have since found it very useful.... :)
[james28909]: ill be back with a solution eventually

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2017-04-29 04:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (531 votes). Check out past polls.