Hi everyone.
I came across a problem whilst I was writing a module which is basically an extension (subclass) of IO::File. In order for my module to work correctly, I needed to know the name of the file which was requested to be opened. Now, whilst I have successfully subclassed IO::File, I needed a way of ensuring that the filename which is passed to my module was a "well-bahaved" plain file. The method I chose was simply to do a file test on the filename (-f). An example testcase illustrating the problem is shown below.
# ensure the file exists open FILE, ">testfile.log" || die "Unable to create file: $!"; close FILE; # test 1 if (! -f "<testfile.log") { print STDERR "Not a file <.\n"; exit; } # test 2 if (! -f ">>testfile.log") { print STDERR "Not a file >>.\n"; exit; } print "I shouldn't be here.\n"; exit; __END__
Whilst this works as I expected on Unix:
Not a file <.
When I run the same code on ActiveState 5.8 on Windows, I receive the following response:
Not a file >>.
Which means that "test 1" above returned false. Does anyone know if this is defined behaviour, or a bug?
Also, would anyone like to suggest an alternative approach, or have any pointers to any further info on this?
Thanks for everyone's time.
Cheers,
-- Dave :-)
$q=[split+qr,,,q,~swmi,.$,],+s.$.Em~w^,,.,s,.,$&&$$q[pos],eg,print
In reply to Unexpected file test (-f) result on Windows by DaveH
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |