Re: #!/usr/bin/perl -w and use warnings;
by dave_the_m (Monsignor) on Apr 23, 2005 at 13:48 UTC
|
-w turns on warning for the whole Perl program, including any included modules etc; 'use warnings' enables them only in the current lexical scope.
Dave. | [reply] |
Re: #!/usr/bin/perl -w and use warnings;
by japhy (Canon) on Apr 23, 2005 at 13:48 UTC
|
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.
_____________________________________________________
Jeff japhy Pinyan,
P.L., P.M., P.O.D, X.S.:
Perl,
regex,
and perl
hacker
How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
| [reply] |
Re: #!/usr/bin/perl -w and use warnings;
by tlm (Prior) on Apr 23, 2005 at 13:49 UTC
|
| [reply] |
|
Yes, I never thought of that, in that it would be useful to only have warnings for some sections, but the "-w" would be good to check other people modules.
Do I understand that correctly?
Walking the road to enlightenment... I found a penguin and a camel on the way.....
Fancy a yourname@perl.me.uk? Just ask!!!
| [reply] |
|
% perl -wle 'use warnings; { no warnings; $x == 1 } print "ok"'
ok
% perl -Wle 'use warnings; { no warnings; $x == 1 } print "ok"'
Useless use of numeric eq (==) in void context at -e line 1.
Name "main::x" used only once: possible typo at -e line 1.
Use of uninitialized value in numeric eq (==) at -e line 1.
ok
Update: Clarified the original reply.
| [reply] [d/l] |
Re: #!/usr/bin/perl -w and use warnings;
by ambrus (Abbot) on Apr 23, 2005 at 14:01 UTC
|
You've already got the correct answer.
Just one more comment: the -w flag is equivalent to
BEGIN { $^W = 1; }
| [reply] [d/l] |
Re: #!/usr/bin/perl -w and use warnings;
by hubb0r (Pilgrim) on Apr 23, 2005 at 14:09 UTC
|
Plus, with the advent of the warnings pragma, you can use warnings for your entire program, but then locally scope a
no warnings;
or
no warnings qw(uninitialized);
for a block of code where there is a good reason not to use warnings. | [reply] [d/l] |
Re: #!/usr/bin/perl -w and use warnings;
by brian_d_foy (Abbot) on Apr 23, 2005 at 17:06 UTC
|
Besides the other answers, use warnings implicitly requires perl 5.6 or later. People who have to support earlier versions of perl don't use the pragma.
--
brian d foy <brian@stonehenge.com>
| [reply] [d/l] |
|
| [reply] [d/l] |
|
Perl4 had the -w switch, and back then everything fit in one manpage (man perl) so that's where you need to look.
You can still download perl4.036 from CPAN and just look for yourself. You don't have to actually install it :)
--
brian d foy <brian@stonehenge.com>
| [reply] |
|
|
I think -w is usable for all perl 5 versions. Not sure about perl 4 though :-)
| [reply] |
|
| [reply] |
|
| [reply] |
Re: #!/usr/bin/perl -w and use warnings;
by gaal (Parson) on Apr 23, 2005 at 23:03 UTC
|
| [reply] |