Cautionary note for Win32 users. This isn't restricted to Perl use, but I fell foul of it through Perl, so I'll note it here.

I'm generating filenames of the form "path/to/xyz.ext" programmically. The ".ext" part is constant, and the "xyz" are alpha-numeric. My program would run along fine for a while and then just hang.

After much debugging, the realisation seeped into my conciousness that each time the program hung, the current filename was "path/to/PRN.ext" or "path/to/PrN.ext" or some other combination of "(P|p)(R|r)(N|n)" as the filename.

A long forgotten memory recalled that under DOS, the name "PRN" was a pseudo-handle for the (parallel port?) print device, much like "CON" is a pseudo-handle for the console. I also recalled that these pseudo-handles were defined to be "considered to exists at all levels in the directory structure".

What this piece of legacy crap design means is that any attempt to use "PRN" or "prn" (etc.) as a filename (for output), regardless of it being prefixed with a path, and/or postfixed with an extension will result in a successful open. BUT attempting to write to it will attempt to write to the printer. In my case, where there is no printer attached, the write just hangs. I guess it may eventually time out, but if it does, it takes longer than I have the patience to wait.

As a workaround, pre- or post-fixing the name part with any characters, or switching to "ext.PRN" avoids the problem.

I've long enjoyed the shortness of prog >nul relative to prog >/dev/null, but it has it's downside!


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

In reply to Filenames of "PRN" (or "PrN" etc) on Win32. by BrowserUk

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.