akeyes has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using warn() when STDERR is closed
by shawnhcorey (Friar) on Jul 15, 2010 at 16:38 UTC | |
by derby (Abbot) on Jul 15, 2010 at 16:46 UTC | |
by shawnhcorey (Friar) on Jul 16, 2010 at 15:29 UTC | |
by afoken (Chancellor) on Jul 17, 2010 at 09:49 UTC | |
by tye (Sage) on Jul 17, 2010 at 18:12 UTC | |
|
Re: Using warn() when STDERR is closed
by jethro (Monsignor) on Jul 15, 2010 at 16:14 UTC | |
by almut (Canon) on Jul 15, 2010 at 16:27 UTC | |
by JavaFan (Canon) on Jul 15, 2010 at 17:57 UTC | |
by almut (Canon) on Jul 15, 2010 at 18:39 UTC | |
by tye (Sage) on Jul 17, 2010 at 17:36 UTC |