Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^5: Numification of strings

by LanX (Canon)
on Aug 03, 2010 at 13:03 UTC ( #852652=note: print w/ replies, xml ) Need Help??


in reply to Re^4: Numification of strings
in thread Numification of strings

> I guess Ruby and Python need to do it that way because the + operator is overloaded for both numeric addition and string concatenation, while Perl has a separate string concatenation operator, and so there is no ambiguity.

exactly, look at JS to see the mess happening, when you have implicit convertions combined with only one operator for addition AND concatenation.

BTW: Ruby's .to_i and .to_f are closer to Perl than JS parseInt() and parseFloat(). Trying to convert a non-numeric string like "abc" in Perl and Ruby produces 0 but in JS it's NaN (not-a-number) a value which doesn't produce a warning!

perl -we' print 4+"abc"' Argument "abc" isn't numeric in addition (+) at -e line 1. 4

Cheers Rolf


Comment on Re^5: Numification of strings
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://852652]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2014-07-12 00:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (237 votes), past polls