[Israel.pm] Selective warnings use

Mikhael Goikhman migo at homemail.com
Wed Feb 9 07:11:06 PST 2005

On 09 Feb 2005 14:55:12 +0100, Madani, Srikanth, VF-DE wrote:
> Direct use of the $] variable isn't possible because of different
> floating point implementations (as the documentation is kind enough to
> state.)

Direct use of $] is possible, of course. This condition is portable:

  if $] < 5.006;

So, the following line should do what you wanted:

  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.


perl -e 'print+chr(64+hex)for+split//,d9b815c07f9b8d1e'

More information about the Perl mailing list