in reply to Re: Disable Perl warning
in thread Disable Perl warning
.Occasionally, in very rare cases, a certain command may cause a warning that is spurious but unavoidable. In that case, you can enclose just the offending command in a lexical block and silence the warnings there only...
This is a necessary evil. While 99% of the time it's possible to, without jumping through coding hoops, code in such a way that produces no warnings, there is the 1% where the warning comes with the simplest use case:
use strict; use warnings; use List::Util qw( reduce ); print factorial(5), "\n"; sub factorial { return reduce { $a * $b } 1 .. $_[0] || 1; } __END__ __OUTPUT__ Name "main::a" used only once: possible typo at mytest.pl line 10. Name "main::b" used only once: possible typo at mytest.pl line 10. 120
The only reasonable way to squelch that pair of warnings is to put "no warnings;" inside reduce's code block, and yet we're not doing anything even mildly devious.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Disable Perl warning
by choroba (Cardinal) on Nov 27, 2012 at 10:37 UTC | |
by tobyink (Canon) on Nov 27, 2012 at 10:53 UTC |