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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.