Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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?
[Corion]: Discipulus: Well, in many cases it doesn't make sense to build an interface and complicated program just to enter 20 rows into a database ;) But yes, automating data imports should pay off in the long run
[LanX]: Choroba: this happened before I joined, was still in uni, but my boss was summoned to the CEO of the second biggest German bank at that time and could only say " I told them its not ready" ;)
[LanX]: memories....I missed my connection while chatting
[Discipulus]: in this case Corion we are speaking about software licensing: evry year or two we must rescan the whole ced to produce an excel report, while at every activation / disactivation we update a black box DB: i said that i a week i can produce the perl to..
[Discipulus]: rend out the xls IF i have access to the DB
[choroba]: LanX I miss working in a bank sometimes...
[Corion]: Discipulus: Ooof. Especially yearly things are things I like to automate instead of trying to remember how I did things last year...
[Corion]: And the second rule that I've learned is, that there is no one-off job, so writing a program for it pays off almost immediately. The third rule is to give all my programs numbers and have them reproduce that number in the name of their output files. :)
[Discipulus]: the true part is that also specification change between years.. but well our job is cheap but dont abuse of us.. ;=)

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (15)
As of 2017-03-29 12:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (350 votes). Check out past polls.