(tye)Re: use warnings vs. perl -w
by tye (Sage) on Jan 24, 2001 at 18:40 UTC
|
#!/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") | [reply] [d/l] [select] |
|
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 | [reply] [d/l] |
|
| [reply] |
|
|
| [reply] |
|
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.
| [reply] |
|
| [reply] |
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.
--
<http://www.dave.org.uk>
"Perl makes the fun jobs fun
and the boring jobs bearable" - me
| [reply] |
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. | [reply] [d/l] [select] |
|
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.
HTH
Dex
| [reply] |
|
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/perl5db.pl:1521 line 2
-Jim
| [reply] |
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).
andy. | [reply] [d/l] [select] |
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.
| [reply] |