morgon has asked for the wisdom of the Perl Monks concerning the following question:
I have inherited some tangled mess of code that uses barewords for filehandles like so:
The problem is that when the open fails the code goes on (doing many other things) and when it comes to the print Perl emits a warning as FH is not an open filehandle (strict and warnings are on).open FH, ">whatever" or warn "blah"; # much much later print FH "something";
I don't want to go into the code right now, all I want is to suppress the warning, but I cannot write
as FH is a bareword.if(FH) { print FH "something" }
So my question is: What is the idiomatic way to check a such a filehandle?
Many thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: checking bareword-filehandle
by BrowserUk (Patriarch) on Aug 06, 2012 at 14:04 UTC | |
|
Re: checking bareword-filehandle
by moritz (Cardinal) on Aug 06, 2012 at 13:18 UTC | |
by morgon (Priest) on Aug 06, 2012 at 13:24 UTC | |
by moritz (Cardinal) on Aug 06, 2012 at 13:30 UTC | |
|
Re: checking bareword-filehandle
by johngg (Canon) on Aug 06, 2012 at 13:14 UTC | |
by moritz (Cardinal) on Aug 06, 2012 at 13:20 UTC | |
by morgon (Priest) on Aug 06, 2012 at 14:15 UTC | |
by moritz (Cardinal) on Aug 06, 2012 at 14:20 UTC | |
|
Re: checking bareword-filehandle
by ww (Archbishop) on Aug 06, 2012 at 13:46 UTC | |
|
Re: checking bareword-filehandle
by davido (Cardinal) on Aug 06, 2012 at 16:42 UTC | |
|
Re: checking bareword-filehandle
by aitap (Curate) on Aug 06, 2012 at 13:23 UTC | |
|
Re: checking bareword-filehandle
by rovf (Priest) on Aug 06, 2012 at 14:59 UTC |