Perl: the Markov chain saw | |
PerlMonks |
Re: When does '123' become the number 123.0?by radiantmatrix (Parson) |
on Jun 17, 2008 at 18:28 UTC ( [id://692564]=note: print w/replies, xml ) | Need Help?? |
I'm reading a comma-separated-value ascii text file containing numerical data, e.g. "123,234,456" on 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:
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.
<–radiant.matrix–>
Ramblings and references “A positive attitude may not solve all your problems, but it will annoy enough people to make it worth the effort.” — Herm Albright I haven't found a problem yet that can't be solved by a well-placed trebuchet
In Section
Seekers of Perl Wisdom
|
|