On Mon, 08 Nov 2010, E. S. wrote:
> Opening a file named "con" (possibly followed by a dot and some
> extraneous characters) for writing from within perl does not signal an
> error, even though windows doesn't allow it. Instead, the opened file
> handle acts as if everything is OK - you may write to it, close it,
> select it, flush it, wine and dine it. You may even spend an hour
> trying to figure out why, when all of these things happen without
> error, your file doesn't actually exist when your program is finished
> (until you realize what silly things your operating system is doing or
> preventing you from doing).
>
> I'm using the portable version of strawberry out of the box on win
> xp. Another more serpentine language gives a permission error when
> trying to open 'CON.dat' (or any of the various other problematic DOS
> names). This annoyed me enough to post here: Anybody know of a way to
> make perl gag when trying to open the special, un-openable DOS files
> like CON?

You can use the "-c" file test to check if open() returned a handle to
a regular file, or to a character mode device (like nul, aux, lpt1, com1
etc).

If you want to automate this for all open() calls, then check into
subclassing the autodie module to add that check.

If you don't want to add "use autodie" to your module, either add
-Mautodie to your PERL5OPT environment variable, or add the use
statement to your Perl/site/lib/sitecustomize.pl file.

Cheers,
-Jan


Reply via email to