Re^2: true from (-e "") on Windoze
by CountZero (Bishop) on Jul 02, 2012 at 19:12 UTC
|
That won't work. Empty double quotes in a string are considered "true" by Perl.
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James My blog: Imperial Deltronics
| [reply] |
|
|
| [reply] [d/l] |
|
|
Yep, it's the quotes-within-quotes that is the problem.
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James My blog: Imperial Deltronics
| [reply] |
Re^2: true from (-e "") on Windoze
by CarolinaPerler (Acolyte) on Jul 02, 2012 at 19:15 UTC
|
if ($file) returns true, also because the variable has content, two double quotes.
I think I'm going to have to just check to see if my $file variable contains a pair of double quotes and only a pair of double quotes. 'Seem like a hack, though. 'Seems like the '-e' test operator would return false on this case.
That's what makes me wonder if Windoze actually uses the empty double quotes as some kind of file system object/entity. That would make the '-e' test think the empty-double-quote-thing was real and existed..... Don't know that much about the various file system types and how Perl on Windows handles them.
| [reply] [d/l] |
|
|
Windows uses double quotes to solve a problem caused by file (or directory) names which contain spaces.
dir "C:\Program Files\" Works as intended
dir C:\Program Files\ File not found
dir "" Displays current directory
| [reply] [d/l] [select] |
|
|
OK, how about this? (I've tested and it is working correctly for $file = '""'; on OS X.)
for ($file) {
say "nope (empty quotes)" when /""/;
say "yep" when -e $file;
default { say "nope (doesn't exist)"}
}
| [reply] [d/l] [select] |
|
|
Yeah, the odd behavior only occurs on Windoze. UNIX/Linux/Mac work just as you'd expect, returning false for the '-e' on a pair of empty double quotes.
| [reply] |
|
|
|
|
| [reply] [d/l] [select] |
|
|
Ya, I didn't catch that they were quotes within quotes. Out of curiosity, why/how is that happening?
| [reply] |
|
|
My code is being fed, so to speak, by another application over which I have no control. Every now and again, when the feeder is asked for a list of files, it returns one or more elements in the array that contains just a pair of empty double quotes.
Oddly, at a Windows command prompt, you can do 'cd ""' and it does not complain. It doesn't go anywhere, but, it doesn't complain.
| [reply] |
|
|
Re^2: true from (-e "") on Windoze
by CarolinaPerler (Acolyte) on Jul 02, 2012 at 19:09 UTC
|
Yes, it does. If I put anything between the quotes, I get the expected results. It is just the empty double quotes that unexpectedly returns true from '-e'. | [reply] |