Hi,

Got a quick question that I was wondering if you guys might be able to help with.

I had a case recently where I was working on some code where I was using warn, however STDERR was closed. warn() seemed to pick up the next opene file handle in my application and print to that.

I'm not good at explaining things so the following one liner shows the behaviour I am talking about

$ perl -le 'close(STDERR); open AA, ">/tmp/stderrtest"; warn "Hello"; +close AA;'; cat /tmp/stderrtest Hello at -e line 1. $

As you can see, warn wasn't able to output to STDERR, but instead printed out to the AA filehandle and printed the Hello message into /tmp/stderrtest

Outputting to another file handle because STDERR is closed seems like dangerous behaviour to me, and could lead to very strange problems and data corruption, if you have a lot of file handles open. I would have thought an error would have been more appropriate.

My question was really just if anyone was aware of this behaviour? Should this happen (or is it a bug)? and if it's not a bug does anyone know the reasoning behind warn() working like this?

Thanks for your help
Al


In reply to Using warn() when STDERR is closed by akeyes

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.