Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
but surprisingly it doesn't - this emits warnings. Why is that?

My guess is that this has the same scope problems that no warnings 'deprecated' has.

It seems the -X of the shebang-line takes effect even though you explicitly invoke perl on the command line. Is that so?

From DESCRIPTION in perlrun:

The #! line is always examined for switches as the line is being parsed.

Finally I would be interested if there is a way to globally disable specifically the deprecation warnings only.

I'm hoping someone can offer up a more elegant solution, as the following seems a little fragile/hackish. In order to filter out deprecation warnings, I've put in a BEGIN block with a second internal block with a localized WARN handler. Since perl compiles each module at most one time, this catches the emitted warnings on the first compile. The regular expression then filters out any newline-delimited portion of the emitted warnings that contain the word deprecated. Note that swapping from a require to a use will make the following code fail to catch the warnings, at least on my machine.

BEGIN { my $initial_warnings = ""; { local $SIG{__WARN__} = sub{$initial_warnings .= $_[0]}; require Foo; } $initial_warnings =~ s/^.*deprecated.*$ \n?//xmg; warn $initial_warnings if $initial_warnings; } use Foo;

In reply to Re: Supressing warnings by kennethk
in thread Supressing warnings by Anonymous Monk

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2023-03-22 13:05 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (60 votes). Check out past polls.