in reply to shebang arguments

Another difference is that if someone runs the perl command against your script then the shebang line will be ignored while "use warnings" will still be enforced. This is particularly relevant on Windows which does not use the shebang line.

My personal view is that the -w method is "old school" and these days you should be using the warnings pragma instead.

Replies are listed 'Best First'.
Re^2: shebang arguments
by friedo (Prior) on Jul 03, 2008 at 00:21 UTC

    Another difference is that if someone runs the perl command against your script then the shebang line will be ignored while "use warnings" will still be enforced.

    It may be ignored by the shell, but it isn't ignored by perl.

    foo.pl: #!/usr/bin/perl -w $x = $y . $z; $ ./foo.pl Name "main::y" used only once: possible typo at ./foo.pl line 3. Name "main::z" used only once: possible typo at ./foo.pl line 3. Name "main::x" used only once: possible typo at ./foo.pl line 3. Use of uninitialized value in concatenation (.) or string at ./foo.pl +line 3. Use of uninitialized value in concatenation (.) or string at ./foo.pl +line 3. $ perl foo.pl Name "main::y" used only once: possible typo at foo.pl line 3. Name "main::z" used only once: possible typo at foo.pl line 3. Name "main::x" used only once: possible typo at foo.pl line 3. Use of uninitialized value in concatenation (.) or string at foo.pl li +ne 3. Use of uninitialized value in concatenation (.) or string at foo.pl li +ne 3.

    BTW, you can use perl -X to force it to ignore -w on the shebang, if you want.

      Ahh, so perl actually checks! Nice!
Re^2: shebang arguments
by DrHyde (Prior) on Jul 03, 2008 at 10:01 UTC

    Just because something is old and there's a new way of doing it doesn't mean that you should abandon the old. For one thing, 'use warnings' won't work on some older perls. If you care about them - and I do - then 'use warnings' is a bad idea.

    I do 'use warnings' when developing my code, but I try to remember to remove it when I do a release. I usually forget and am prompted to do so by test failures being reported by the CPAN testers. Quite often those failure reports come from my own testing boxes :-)

      I agree that just because something is new does not automatically mean you should abandon the old method in favor of it. But on the other hand if a paradigm shift occurs then it likely means the new way is the better way. And in this case the impression I get is that the Perl community has shifted away from -w in favor of the warnings pragma. Hence why I called -w "old school".

      I think it goes without saying that you would use "old school" methods with older versions of Perl. That's part of what "old school" implies.

      P.S. Sounds like you should firewall off your test servers! ;-)