I'm reading a comma-separated-value ascii text file containing numerical data, e.g. "123,234,456" on each line.I'm using 'split' to separate the fields of each line
Don't do that. Use Text::CSV_XS. CSV files will bite you if you're not careful.
Is it the string "123" or the number 123.0? And does it make any difference to the perl programmer?
It's a scalar. Don't worry about how it's stored under the hood, it will be a string or an integer or a float when you need it to be one of those things.
Under the hood, since you're using split, you'll be getting strings. But:
my $line = '123,456,789'; my ($val) = split(',' , $line); # $val is the string '123' $val += 2; # $val is now the integer 125 $val /= 2; # $val is now the float 62.5 print "I ended up with $val" # $val is treated as the string '62.5 +'
The whole point of Perl's weak typing is that you don't have to worry about this sort of thing. If you want to validate that your scalar contains a certain type of data (not under the hood, mind you), check out Data::Validate.
In reply to Re: When does '123' become the number 123.0?
by radiantmatrix
in thread When does '123' become the number 123.0?
by wa1ter
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |