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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.