Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

use warnings vs. -w

by earthboundmisfit (Chaplain)
on Jun 09, 2001 at 00:35 UTC ( #87062=perlquestion: print w/replies, xml ) Need Help??

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


Camel book tells me use warnings; is better than the -w line command (p.862 in the 3rd edition).

I mostly exist in a Win32/web served world, so I'm happy to comply.

Is there some hidden advantage to -w or is it a Unix vs. Windows convention or simply a finer grain with the warnings pragma?

Replies are listed 'Best First'.
Re: use warnings vs. -w
by wog (Curate) on Jun 09, 2001 at 00:43 UTC
    The warnings pragma was added in perl version 5.6. Putting #!perl -w at the top of your script is slightly different then use warnings. That difference is that use warnings is lexically scoped (like my variables, so that you can require without warnings being on in the require'd file.) while -w stays on unless explictly turned off with the special $^W variable. (Which the warnings pragma is probably more convient then.)
Re: use warnings vs. -w
by virtualsue (Vicar) on Jun 09, 2001 at 00:57 UTC
    perllexwarn contains a good explanation of use warnings; and the advantages it provides over enabling warnings via -w & $^W.
Re: use warnings vs. -w
by dragonchild (Archbishop) on Jun 09, 2001 at 00:57 UTC
    However, to round out the thought, if you do use the warnings pragma, make sure you require a specific version of Perl. Something like:
    use 5.6.0; use warnings;

    That way, someone else using your script on another machine doesn't have a nasty surprise. (Personally, I think every production-level script should demand a specific Perl version, even if you know what will happen. You never always know ... ever.)

      Version strings, the feature that allows you to write 5.6.0, were also added in 5.6.0. Thus: use 5.6.0; will fail in a strange way with older versions of perl: Can't locate 5.60 in @INC (@INC contains: /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_perl/5.005/i386-linux /usr/lib/perl5/site_perl/5.005 .) at -e line 1.

      I find it quite frustrating that a feature that is supposed to handle issues of backward compatibility was updated in a non-backward compatible way. :(

      Here's the backward compatible way to require 5.6.0: use 5.006;

        Um, it is backward compatible, and it should be: require 5.006; It just isn't forward compatible, as few things are.

                - tye (but my friends call me "Tye")
Re: use warnings vs. -w
by tachyon (Chancellor) on Jun 09, 2001 at 01:00 UTC

    You may like to click this link use warnings vs. perl -w to check out an extensive previous discussion of this issue including the Win32 subject. Note you need Perl 5.6.0 or greater to "use warnings" so this is not yet all that portable as many people still use older versions.



      Eeek! How many floggings do I receive for failure to search that previous discussion out for myself? :)

      Many thanks, all.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2022-08-16 00:46 GMT
Find Nodes?
    Voting Booth?

    No recent polls found