[Israel.pm] Selective warnings use
Madani, Srikanth, VF-DE
Srikanth.Madani at vodafone.com
Thu Feb 10 01:49:47 PST 2005
Mikhael Goikhman wrote:
>Direct use of $] is possible, of course. This condition is portable:
> if $] < 5.006;
True, thanks.
>So, the following line should do what you wanted:
> eval "use warnings;" if $] >= 5.006;
I can't seem to get this to work. Can you please explain the behaviour
below:
DevSet> cat war4.pl
#!/usr/local/bin/perl
use strict;
eval "use warnings;" if $] >= 5.006;
print "\nThe value of warnings is $^W\n";
$a =+ 2;
DevSet>
DevSet>
DevSet> ./war4.pl
The value of warnings is 0
DevSet>
The reversed operator causes no concern here. Whereas, if I use the
"warnings" pragma directly (as opposed to eval'ing it):
DevSet> cat war41.pl
#!/usr/local/bin/perl
use strict;
use warnings;
print "\nThe value of warnings is $^W\n";
$a =+ 2;
DevSet>
DevSet>
DevSet> ./war41.pl
Reversed += operator at ./war41.pl line 5.
Name "main::a" used only once: possible typo at ./war41.pl line 5.
The value of warnings is 0
DevSet>
Both these snippets were run on version 5.008001 (Perl v5.8).
>Similarly, $^W = 0; may be used for "no warnings;". But this is not the
>official way, working with this variable directly is not very portable.
That's what I found too. A 'use diagnostics' pragma affects the value of
this variable, globally.
Anyway, this whole thread is basically about style and portability. :-)
Thanks,
Srikanth Madani
More information about the Perl
mailing list