I tried the code sample you provided, and the results are the same (as you know). 'Normal' behavior for open/fopen in C/unix is to use the lowest available file descriptor. However, when I run it, either on 5.8.4 or 5.6.0, the behavior is the same: STDOUT gets fd 1, even though fd 0 is available. If I open another file before re-opening STDOUT:
open STDIN, "<$file" or die "can't open STDIN from $file - $!\n"; my @data = <STDIN>; my $chk1 = sprintf "STDIN file num is %d", fileno(STDIN); print STDERR $chk1."\n"; close STDIN or die "error closing STDIN - $!\n"; open TMP, "<$file"; $chk1 = sprintf "TMP file num is %d", fileno(TMP); print STDERR $chk1."\n";
I get what you would expect: the same result, but without the warning. I think the warning is telling you that perl won't violate the conventions that ikegami mentioned. You could get around this fairly easily if you simply move the close of STDIN to follow the open of STDOUT. Keep in mind, though, that by doing this, fd 0 becomes available, and you will get the same warning if the next open is not read-only.

As ikegami said, don't mess with the STD* filehandles unless you doing an exec.


In reply to Re: Odd error message at 5.8.3 by Illuminatus
in thread Odd error message at 5.8.3 by damercer

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.