Hi perlmasters,

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 into three arrays e.g. ($a[$i], $b[$i], $c[$i]) where $i is the line number.

My question is, what is actually stored in $a[$i]? Is it the string "123" or the number 123.0? And does it make any difference to the perl programmer?

I'm using the results entirely in numerical calculations, so I want to do all conversion of string-to-number (if any) at the time I read the file and get it over with early.

I've been using the perl debugger to print these variables but I can't (yet) tell whether it's printing a string or a number.

If the perl docs answer these question explicitly I've missed it, so please point me to the appropriate docs.

Thanks for your time!


In reply to When does '123' become the number 123.0? by wa1ter

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.