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

use warnings vs. perl -w

by dmckee (Scribe)
on Jan 24, 2001 at 16:13 UTC ( #53947=perlquestion: print w/ replies, xml ) Need Help??
dmckee has asked for the wisdom of the Perl Monks concerning the following question:

It is stated in the book of man perl
Thou shalt use perl -w before moaning about Perl.

However, I'm using Windows, so it's trickier to run -w, and I can't use the #!perl -w trick except under Apache. Are there any reasons why the use of 'use warnings' appears to be depreciated? (Naturally, I bung it in at the top of my code, along with 'use strict')

Comment on use warnings vs. perl -w
Re: use warnings vs. perl -w
by Caillte (Friar) on Jan 24, 2001 at 16:26 UTC

    There are a number of options. Use pl2bat then edit it so it calls the script with the -w switch or, during development, run the program - i know this is a horrible thought for doze users ;) - from the command line. Finally, you could edit the file-types entry for perl in windows explorer's options; simply add a -w switch for the open option.

Re: use warnings vs. perl -w
by andye (Curate) on Jan 24, 2001 at 16:26 UTC
    To switch on warnings when you can't use -w, use $^W=1 instead. Or if you use english then $^W is called $WARNING. You can limit the scope of your change by using local inside a block (e.g. if you wanted to switch off warnings in a limited scope).


Re: use warnings vs. perl -w
by davorg (Chancellor) on Jan 24, 2001 at 16:39 UTC

    use warnings and -w do very similar things. use warnings was introduced in Perl 5.6 and is definitely the way to go. The only reason to stick with -w is if your scripts might be run using an older version of Perl.


    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me

(tye)Re: use warnings vs. perl -w
by tye (Cardinal) on Jan 24, 2001 at 18:40 UTC

    Under Windows you should start all of your scripts with

    #!/usr/bin/perl -w
    Surprised? Note that this won't tell the operating system to look for perl.exe in the /usr/bin directory. It will tell perl to turn on warnings, even on Windows, even without Apache. Oh, when using Apache, you'd want the real path to perl.exe instead of /usr/bin/perl, since, as you know, Apache looks at the #! line.

    I don't use warnings as that will prevent my code from compiling prior to Perl 5.6 and it is still way too early to yell at anyone for running pre-5.6 versions of Perl. (:

            - tye (but my friends call me "Tye")
      You're right, it does work, but I just tried this:
      #!/usr/bin/perl -w print "Content-Type: text/html\n\n"; $t = "hello world"; print "$h, $t";
      It doesn't complain about $h being uninitialised. It does however, if you take out the HTTP header.

      Update: I was running this on a Win32 webserver.

      Is that the way it should be?

      $code or die
      Using perl at
      The Spiders Web

        For me it complains either way, as it should.

                - tye (but my friends call me "Tye")
        If you are running under a webserver, the non-fatal errors my be hiding in the error log of your server or may even have been piped away to nothing, rather depends on the webserver. Check the error logs and see.

        $you = new YOU;
        honk() if $you->love(perl)

        These days, the -w command line flag is usually replaced with the warnings pragma, as the latter is more flexible, and has scope that is limited to the enclosing block, while -w is global in effect.

      And here I was thinking it was time to yell at people for not using 5.8.0 RC3 in production. For that matter, Sean O'Rourke has submitted a Perl6 grammar patch to Parrot. <grin>

Re: use warnings vs. perl -w
by chipmunk (Parson) on Jan 24, 2001 at 19:23 UTC
    As tye said, you can use #!perl -w on Windows. In fact, you can use the #! line on any platform to specify options. perlrun explains why:
    The #! line is always examined for switches as the line is being parsed. Thus, if you're on a machine that allows only one argument with the #! line, or worse, doesn't even recognize the #! line, you still can get consistent switch behavior regardless of how Perl was invoked, even if -x was used to find the beginning of the script.
    perl itself parses the #! line, even if the operating system ignores it. There are a few other tricks perl does with the #! line, also described in perlrun.
      You can also apply '-w' in the file association if you are concerned. Go to "Tools - Folder Options - File Types". Find your PL entry. Edit the Open property and add '-w' and whatever other options you want by default.

      Of course, you could also set this programatically via perl.

      As I recall, before the Grand Unification of AS and GS Win32 perl distributions, you had to add it for GS, though I could be mistaken.


        Has anyone ever tried using $^W. I never have but it from "perl -d -e 0" I've done this: print "$junk" --- No output $^W = 1 print "$junk" --- Use of uninitialized value in string at (eval 7)C:/Perl/lib/ line 2 -Jim

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2014-08-23 20:22 GMT
Find Nodes?
    Voting Booth?

    The best computer themed movie is:

    Results (178 votes), past polls