Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Supressing warnings

by kennethk (Abbot)
on Jul 22, 2010 at 14:50 UTC ( [id://850861]=note: print w/replies, xml ) Need Help??


in reply to Supressing warnings

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;

Replies are listed 'Best First'.
Re^2: Supressing warnings
by morgon (Priest) on Jul 22, 2010 at 21:22 UTC
    The #! line is always examined for switches as the line is being parsed.

    Funny, I never knew that. It does not even need to contain a path to perl, all it needs is an occurance of the string "perl".

    If a.pl e.g. starts with "#!end lines properly! -d", then "perl a.pl" starts the debugger.

    I hope I find a way to turn this knowledge into a beer at the upcoming YAPC::Europe (even though I think this behavour does not really makes sense).

      I think this behavour does not really makes sense

      I'd say it makes a lot of sense :)

      (For example, at 5.8 times when there was no say, -l was one of my favorite options to put in the shebang line for short test scripts.)

        Yeah, ok there may be some uses like yours (which I would consider a hack), but in general (at least that would be the behaviour of least surprise) you (ok: I) would expect that when you run a script as "a.pl" you get your command-line flags from the shebang-line and when you run it as "perl <whatever flags> a.pl" your get it from - well - the command line.

        With this behaviour I cannot run a script with different flags without having to modify it if it contains a shebang lines with flags.

        Do Python and Ruby do this as well?

        #!/home/mh/perl512/bin/perl -w warn "Hubba\n"; # script a.pl, produces warning

        When you run this as "perl -X a.pl" you still get the warning - even though -X should disable them.

        Is that because -w (from shebang) is "stronger" than -X (from command line)?

        UPDATE:

        The above is crap - sorry.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2024-03-19 06:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found