oxone has asked for the wisdom of the Perl Monks concerning the following question:
I know that a string of chars will evaluate to zero in a numeric context, but it does so with a warning, eg.
use strict; use warnings; my $val1 = 'Test'; my $val2 = '5.6'; # $val1 += 0; # How to numerify $val1 without a warning? print "Sum is ", $val1 + $val2, "\n";
The example prints the right answer (5.6) but also issues a warning about the $val1 scalar being non-numeric. I've tried using +=0 and similar to safely numerify it first, but that gets me a warning too.
Is there a trick to doing that? Or it is a case of temporarily turning off warnings?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Warning-free numerification of a string
by Fletch (Bishop) on Aug 08, 2007 at 18:32 UTC | |
|
Re: Warning-free numerification of a string
by clinton (Priest) on Aug 08, 2007 at 18:42 UTC | |
by oxone (Friar) on Aug 08, 2007 at 19:19 UTC | |
by clinton (Priest) on Aug 08, 2007 at 19:24 UTC | |
|
Re: Warning-free numerification of a string
by ikegami (Patriarch) on Aug 08, 2007 at 18:45 UTC | |
by oxone (Friar) on Aug 08, 2007 at 19:21 UTC | |
by syphilis (Archbishop) on Aug 09, 2007 at 03:02 UTC | |
by varian (Chaplain) on Aug 08, 2007 at 22:09 UTC |