How does warn 4
differ from print STDERR 4
?
perl -e 'local *STDERR; warn 4'
(output still goes to STDERR
)
perl -e 'local *STDERR; print STDERR 4'
(no output here)
warn
triggers $SIG{__WARN__}
.warn
doesn't use $\
or $,
.warn
apparently uses the file handle in the original STDERR
, as you've demonstrated[1].Not quite. Your code could also demonstrate that warn
uses fd 2 directly, but that's disproven by
close(STDOUT);
close(STDERR);
open(STDERR, '>file');
warn(fileno(STDERR)."abc"); # 1abc
You haven't silenced the STDERR
handle yet. In order to really silence it, you need to say:
perl -e 'local *STDERR; open(STDERR, ">/dev/null") or die $!; warn 4'
perldoc perlvar
tells:
As the
'IGNORE'
hook is not supported by__WARN__
, you can disable warnings using the empty subroutine:local $SIG{__WARN__} = sub {};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With