Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

So how do I know if "1" gets added to a 0 or to an empty string?


Perl uses separate operators for mathematical addition and string concatenation.

  1 + 1 == 2;
  1 . 1 eq 11;
It uses separate operators for most mathematical and string operations, for that matter. There isn't much of a meaningful difference between strings and numbers in Perl -- it converts between then depending on the operation.


I suppose there's some type inference there and you'll get the default be 0 since 1 is also an integer, not a string.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: