Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re^4: Numification of stringsby eyepopslikeamosquito (Archbishop) |
on Aug 03, 2010 at 04:54 UTC ( [id://852595]=note: print w/replies, xml ) | Need Help?? |
Yes, I guess it is explicit in Perl. In terms of language design, the interesting question is whether the Python/Ruby demand to explicitly cast/coerce by calling int is "stronger/safer typing" or "ugly explicit casting" (frowned upon in C++, for example). Let's clarify with a little test program. In Perl, running: produces: That seems reasonable to me. In Python, running: produces:
while running: also fails with: Python's int function is stricter in what it accepts than Perl and Ruby. Finally, running: produces the desired result:
In Ruby, running: produces: Just like Python. While running: produces: Ruby's to_i method being less strict than Python's int function. 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. Update: Python's stricter typing can produce other subtle differences. For example, in Python both 5 * "X" and "X" * 5 produce five Xs. Not so in Perl or Ruby. That is, the string multiply operator is commutative in Python, but not in Perl or Ruby. Not sure if string multiply commutativity is a bug or a feature. Curiously, the new Perl 5.10 smart match operator ~~ was commutative in Perl 5.10.0, then that was deemed a mistake and it was made non-commutative in Perl 5.10.1.
In Section
Seekers of Perl Wisdom
|
|