[Israel.pm] Re: Selective warnings use
Roie Marianer
roiem at actcom.co.il
Thu Feb 10 02:06:08 PST 2005
Srikanth Madani asked
> #!/usr/local/bin/perl
> #Notice that I haven't used the "-w" flag
> use strict;
> use diagnostics;
> use warnings if ($Check_if_warnings_pragma_is_available);
> Use the "-w" flag, if warnings isn't available.
Mikhael Goikhman noted:
> You can't simply write "use warnings" (that is executed on compile time)
> together with a condition (that is executed on run time), you need eval.
But the "perlfunc" manual says:
> ...It is exactly equivalent to
> BEGIN { require Module; import Module LIST; }
So I tried:
| #!/usr/local/bin/perl
| use strict;
| BEGIN { if ($] >= 5.006) {
| require warnings; import warnings; print "enabling warnings\n"
| }}
| print "$]\n";
| print "\nThe value of warnings is $^W\n";
| $a =+ 2;
and got this:
| Reversed += operator at - line 8.
| Name "main::a" used only once: possible typo at - line 8.
| enabling warnings
| 5.008006
|
| The value of warnings is 0
on Perl 5.8.6 (sorry, I don't have an older version of Perl to test it with).
It seems this version of Perl uses ${^WARNINGS} instead of $^W in warnings.pm,
which is why $^W remains 0.
Only one question remains: Does anyone know what "Reversed += operator" means?
-R
More information about the Perl
mailing list