Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Difference between warnings pragma or enabling warnings using -w switch?

by gube (Parson)
on Aug 30, 2005 at 05:01 UTC ( [id://487643]=perlquestion: print w/replies, xml ) Need Help??

gube has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,

In cgi programs some programs using switch -wT for warnings and Taint. some programs they use the warnings pragma. Both methods are for enable warnings. so, what is the difference between the two. And which one is best using these switch case or pragma.

  • Comment on Difference between warnings pragma or enabling warnings using -w switch?

Replies are listed 'Best First'.
Re: Difference between warnings pragma or enabling warnings using -w switch?
by rupesh (Hermit) on Aug 30, 2005 at 05:16 UTC

    gube,

    The -T command line switch turns on taint checking, something that's useful for CGIs when you want to make sure there's no user input that can possibly flow through to the operating system for security reasons. Typically you want to enable taint-checking as early in the command line options as possible.

    -w enables warnings globally for the perl interpreter. It can be used for code that needs to maintain compatability with 5.005 and older perls, but for newer code, use warnings is better, because it will not enable warnings in parts of the program that are not designed to be run with them enabled.

    The -w has a global effect on your entire program. The warnings pragma was introduced in Perl 5.6 and allows for scoped sections of warning-enabled code, with the ability to turn on and off specific classes of warning messages.
    On more information on use warnings, you can visit this node --> here.

    Cheers,
    Rupesh.
Re: Difference between warnings pragma or enabling warnings using -w switch?
by tlm (Prior) on Aug 30, 2005 at 10:24 UTC
Re: Difference between warnings pragma or enabling warnings using -w switch?
by pg (Canon) on Aug 30, 2005 at 05:31 UTC

    Create two pieces of code, test1.pl and blah.pm:

    use warnings; use blah; sprintf("%d\n", 1); #this is always warned, as it is in a scope with " +use warnings" declared

    And here is blah.pm:

    package blah; sprintf("%d\n;", 1); 1;

    Run perl test1.pl, you get:

    Useless use of a constant in void context at test1.pl line 5.

    With perl -w test1.pl, you get:

    Useless use of a constant in void context at blah.pm line 3. Useless use of a constant in void context at test1.pl line 5.
      i'd like to add, that you could say no warnings; in blah.pm, which would turn off the warnings for the enclosing block.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-24 00:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found