On Sun, 15 Mar 2015 21:11:05 +1300
Kent Fredric <kentfred...@gmail.com> wrote:

> On 15 March 2015 at 20:07, Manfred Lotz <manfred.l...@arcor.de> wrote:
> 
> > I prefer the method Charles showed. But nevertheless your method is
> > interesting as well.
> >
> 
> FWIW, SIG{__WARN__} is much preferred over redirecting stderr to
> simply suppress/capture/filter warnings.
> 

I agree but I thought that in this case I would need to know the
potential warning messages the :encoding(UTF-8) could issue in order to
take action in those particular cases.

Using a section local 
{
   open( local *STDERR,'>', $err);
...
}

gives me more control.


> For instance, if somebody passes an object to warn, context will not
> be captured if you're piping STDERR.
> 
> And capturing STDERR has side effects, and potential complications.
> 

I agree that capturing STDERR would be really bad if I would do it in a
module as I don't know in which way others would use the code.


> With SIG{__WARN__}, you can at least observe the warning, and reemit
> it.
> 

As said above, then I would need to know the possible warning text in
order to intercept them.


> See `perldoc -f warn` for details.
> 
> But SIG{__WARN__} very much was designed with the purpose of
> processing warnings.
> 
> And if you just want to silence them, you can do $SIG{__WARN__} =
> "IGNORE";
> 

I used SIG{__WARN__} successfully in another script where for some
reason I wanted to be a warning be fatal.


> Just make sure you use local so you don't mess up other peoples warn
> handlers in higher contexts when you're done.
> 

Yep, in this case it would be bad.


Thanks for drawing the focus to this aspect.


-- 
Manfred






-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to