in reply to Re: Fun with Numbers
in thread Fun with Numbers

It's all pretty much defined behavior. Any language that makes thin distinctions between strings and numbers (as Perl does) needs to have some defined way of what strings do when they're applied to numbers, and what numbers do when applied to strings. You might take issue with the way Perl does that, and you might take issue with the fact that Perl doesn't have a value-based type system.

But it's all well-defined and documented (more or less).

"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Replies are listed 'Best First'.
Re^3: Fun with Numbers
by Joost (Canon) on Feb 11, 2005 at 22:08 UTC
    What I was getting at, is that in general perl promotes a number at the start of a string to the same number as if it was a literal. I was suggesting that since it doesn't in this case, you could consider it a bug.

    I do consider it a bug, but I would not consider changing the current behaviour before perl6, because of backward compatibility. It would break too subtly in too many scripts.

    As an example of "working" DWIM:

    my $i = 1234e3; my $j = "1234e3"; print join("\n",$i, $j, 0+$i, 0+$j);