in reply to true from (-e "") on Windoze

Does it work as expected if you type in some random letters between the quotes? I don't use Windows, but one way you could get around this is something like:
if ( $file and -e $file ) { say "yep"; } else { say "nope"; }

Replies are listed 'Best First'.
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
      Works fine for me. Also, here is a handy table for this sort of thing: "Truth tests for different values" on True or False? A Quick Reference Guide. defined $file, however, would be true for an empty string.

      edit: Oops, I didn't catch that there were quotes inside quotes...

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

      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

      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)"} }
        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.
      I think you're misinterpreting comments preceding Re^2: true from (-e "") on Windoze; I think the fact that the VALUE of $file is -- per se -- true is borking your expectations.

      I don't recall any version of windows accepting "" or '""' or """" as a filename or filename element ...or any of the DOS/doze FS using "", et al, for anything.

      Ya, I didn't catch that they were quotes within quotes. Out of curiosity, why/how is that happening?
        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.
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'.