[Israel.pm] Selective warnings use
Gaal Yahas
gaal at forum2.org
Wed Feb 9 12:04:24 PST 2005
On Wed, Feb 09, 2005 at 03:11:06PM +0000, Mikhael Goikhman wrote:
> eval "use warnings;" if $] >= 5.006;
>
> 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.
>
> I don't suggest this however, since your code will omit warnings in
> 5.00503. Personally, I use "-w" in scripts intended for older perls.
> Another solution is to replace "use warnings;" with this line:
>
> BEGIN { $^W = 1; }
>
> 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.
You can pull a re-exec() trick. Off the top of my head, and obviously
not tested:
#!/usr/bin/perl
BEGIN {
if ($] < 5.006) {
if (($ARGV[0]||"") ne "__hack__")) {
exec $^X, $0, "__hack__", @ARGV;
} else {
eval "use warnings; 1" or die $@;
}
}
--
Gaal Yahas <gaal at forum2.org>
http://gaal.livejournal.com/
More information about the Perl
mailing list