<?xml version="1.0" encoding="windows-1252"?>
<node id="994574" title="Re^11: true from (-e &quot;&quot;) on Windoze (&quot; is an illegal filename character" created="2012-09-19 21:58:21" updated="2012-09-19 21:58:21">
<type id="11">
note</type>
<author id="524150">
syphilis</author>
<data>
<field name="doctext">
&lt;i&gt;I need a function that checks if file exists&lt;/i&gt;&lt;br&gt;&lt;br&gt;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:
&lt;c&gt;
-T $file || -B $file
defined -T $file
defined -B $file
&lt;/c&gt;
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.)
&lt;br&gt;&lt;br&gt;Someone really ought to file a bug report about this because the &lt;c&gt;perldoc -f -X&lt;/c&gt; documentation does *not* match the behaviour wrt '-e'.&lt;br&gt;That documentation implies that &lt;c&gt;-e '""'&lt;/c&gt; will return true only if a file named &lt;c&gt;""&lt;/c&gt; exists.&lt;br&gt;Either the behaviour ought to change to fit the documentation, or the documentation be amended to fit the behaviour.&lt;br&gt;The documentation also implies that &lt;c&gt;defined -f '""'&lt;/c&gt; will return false (but it doesn't).&lt;br&gt;Here's what I ran as a check:
&lt;c&gt;
#!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";
&lt;/c&gt;
And here's the output I got:
&lt;c&gt;
-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)
&lt;/c&gt;
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).
&lt;br&gt;&lt;br&gt;Cheers,&lt;br&gt;Rob</field>
<field name="root_node">
979494</field>
<field name="parent_node">
994560</field>
</data>
</node>
