Because minus wants numbers and gives a number as a result. So the two parameters are converted to numbers (both zero) and the result is 0. Then print want's a string, so the 0 is converted to "0" which hits your output stream.
—John | [reply] |
(dga: Thanks again. I know what atoi is; I just didn't think of it as the explanation behind the problem.)
John: So maybe I'm confusing you all with how I'm phrasing my questions. Basically, I know what a spark plug is, and I know why the engine doesn't work when the plugs are bad. I guess I just didn't understand why the "horn honked" when this sort of problem occurs. (Not that this is technically a comparable analogy.)
In discussing atoi and the example of 99balloons => 99, why would balloons => 0 instead of null/undef?
| [reply] |
Because null/undef isn't a number. atoi (the C library call) doesn't indicate any kind of error, so the caller can't tell the difference between a string containing "0" and a string containing "balloons". Both make atoi return the int 0, and that's what Perl does (though I think it uses floating point by default; same idea, though).
—John
| [reply] |