Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: no module warnings in client code

by kennethk (Abbot)
on Aug 27, 2013 at 13:46 UTC ( #1051136=note: print w/replies, xml ) Need Help??

in reply to no module warnings in client code

There are missing variables here, such as is this a module you maintain, is it emitting warnings directly or using Carp or other secondary module, does your suggested code work?

In general, the easiest and most appropriate way to silence warnings is to address what the warning is complaining about. Assuming you don't want to do that, your code above would work, assuming that the module does not implement its own warning control. If it does, you can cheat by locally clobbering the warning handler:

{ local $SIG{__WARN__} = sub {#Drop it}; RandomModule::doSomethingThatCanGenerateWarnings(); }

Update: Added some <del> tags following a node update.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Replies are listed 'Best First'.
Re^2: no module warnings in client code
by citromatik (Curate) on Aug 27, 2013 at 14:05 UTC

    Hi kennethk

    My suggested code doesn't work... If it had worked I wouldn't have asked!

    Here is a testing code:


    package tt; use strict; use warnings; sub w { my $str = ""; return substr ($str, 10, 10); } 1;

    Client script:

    use strict; use tt; print tt::w();

    Defining a local warning handler works perfectly:

    use strict; use tt; local $SIG{__WARN__} = sub {}; print tt::w();

    Thanks for the help


      Hi citromatik,
      And you might want to but local $SIG{__WARN__} = sub{}; into a block like kennethk did it.
      If not, you would not receive any other warnings from your client script.
      Just saying ...
      If you tell me, I'll forget.
      If you show me, I'll remember.
      if you involve me, I'll understand.
      --- Author unknown to me

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1051136]
[LanX]: ah yes! And he called her Kit and she could talk while a light was going from her left to right eye and back...
[erix]: choroba: pretty impressive! :)
LanX imagines which nations would be dominating if the winter olympics were invented in East Asia
[LanX]: Corion: and that's the clue how Germany can dominate Handball tournaments, just continuing the domestic league and forbidding the best players of the world to attend :)
LanX (which would be a good scheme for England and football too)
[LanX]: If "Canada will play the Czech Republic for bronze on Saturday", that means Germany will play Syria in disguise...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2018-02-23 16:40 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (303 votes). Check out past polls.