Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Name "main::a" used only once: possible typo

by subogero (Initiate)
on Sep 12, 2017 at 15:56 UTC ( [id://1199215]=note: print w/replies, xml ) Need Help??


in reply to Name "main::a" used only once: possible typo

The best solution I found so far is this
$SIG{__WARN__} = sub { my $w = shift; warn $w unless $w =~ /::[ab]" used only once:/; };
EDIT: An even better one, preserving an already existing signal handler. It still does not guarantee ours won't be overwritten.
my $orig_warn = $SIG{__WARN__}; $SIG{__WARN__} = $orig_warn ? sub { my $w = shift; $orig_warn->($w) if $w !~ /::[ab]" used onl +y once/ } : sub { my $w = shift; warn $w if $w !~ /::[ab]" used only once/ } +;
EDIT: an even shorter one:
my $abwarn = $SIG{__WARN__} // sub { warn shift }; $SIG{__WARN__} = sub { my $w = shift; $abwarn->($w) if $w !~ /::[ab]" used only once:/; };

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1199215]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-09-20 20:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (26 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.