what is actually stored in $a[$i]? Is it the string "123" or the number 123.0?

split returns strings.

And does it make any difference to the perl programmer?

No. It works as intended in practically all cases.

The only time I can think of where it makes a difference is when you use |, & or ^ on it with a string as the other operand.

>perl -le"($x,$y)=map 0+$_, @ARGV; print $x|$y;" 2 8 10 >perl -le"($x,$y)=map ''.$_, @ARGV; print $x|$y;" 2 8 :

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.

It's not needed, but you could use

my @nums = map 0+$_, split /,/;

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.

That just shows you how much it matters.

Devel::Peek will show you. pPOK = string, pIOK, pUOK or pNOK = number. Can be both.

>perl -e"use Devel::Peek; my $x=123; Dump($x);" SV = IV(0x1826628) at 0x225350 REFCNT = 1 FLAGS = (PADBUSY,PADMY,IOK,pIOK) <-- signed int IV = 123 >perl -e"use Devel::Peek; my $x='123'; Dump($x);" SV = PV(0x226154) at 0x225350 REFCNT = 1 FLAGS = (PADBUSY,PADMY,POK,pPOK) <-- string PV = 0x18227c4 "123"\0 CUR = 3 LEN = 4 >perl -e"use Devel::Peek; my $x=123; qq{$x}; Dump($x);" SV = PVIV(0x22718c) at 0x225358 REFCNT = 1 FLAGS = (PADBUSY,PADMY,IOK,POK,pIOK,pPOK) <-- signed int AND string IV = 123 PV = 0x18227cc "123"\0 CUR = 3 LEN = 4

In reply to Re: When does '123' become the number 123.0? by ikegami
in thread 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.