[Israel.pm] Re: Selective warnings use

Madani, Srikanth, VF-DE Srikanth.Madani at vodafone.com
Thu Feb 10 05:35:57 PST 2005


Roie Marianer wrote:

>But the "perlfunc" manual says:
>> ...It is exactly equivalent to
>> BEGIN { require Module; import Module LIST; }

<code snipped>

> on Perl 5.8.6 (sorry, I don't have an older version of Perl to test it
with).

It seems to work just right! Here's sample code:

DevSet> cat war5.pl
#!/usr/local/bin/perl
use strict;
BEGIN {
        if ($] >= 5.006) {
                $^W = 0;
                require warnings;
                import warnings;
        } else {
                $^W = 1;
        }
}
print "\nThe value of warnings is $^W\n";
$a =+ 2;
DevSet>


The corresponding runs on Perl 5.8 is:

DevSet> ./war5.pl
Reversed += operator at ./war5.pl line 13.
Name "main::a" used only once: possible typo at ./war5.pl line 13.

The value of warnings is 0
DevSet>



And on Perl 5.5:

Srik [116]> ./war5.pl
Reversed += operator at ./war5.pl line 13.
Name "main::a" used only once: possible typo at ./war5.pl line 13.

The value of warnings is 1
Srik [117]>


And this is the behaviour I desire.
To recapitulate:
A) To have code portable between versions lower and higer than v5.6
B) To use the warnings pragma, when the version >= 5.6
C) To use the older, deprecated warnings variable ($^W) when running on
an older version of Perl.


> Only one question remains: Does anyone know what "Reversed +=
operator" means?

Just that! Using the diagnostics pragma:

    (W syntax) You wrote your assignment operator backwards.  The = must
    always comes last, to avoid ambiguity with subsequent unary
operators.



Cheers,  
Srikanth Madani




More information about the Perl mailing list