http://www.perlmonks.org?node_id=799634

decebel has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

Here I come again to seek some wisdom on a minor issue that has been bothering me since this afternoon. Basically, I have 2 variables and I am converting them to numbers:

my $store = {}; my $numString1 = '123'; my $num1 = $numString1+0; $store->{'num1'}=$num1; my $numString2 = '123.10'; my $num2 = $numString2+0; $store->{'num2'}=$num2; print Dumper $store;

Below is the output from the print Dumper statement:

{ 'num1' => 123, 'num2' => '123.1' };

As you can see, variable num1 gets converted to a number but num2 is not. num2 value 123.1 is surrounded in quotes and remains as a string.

As a second part of the question, what is an easy way to check if a string is a number and are there any standard ways to convert them to numbers

Thanks a lot in advance, Dece