in reply to Strings & Scalar Context

barewords become strings. "same"-"as" is 0-0 according to atoi, which reads up to the first non-digit then stops without error (e.g. "99 balloons" => 99).

—John

Replies are listed 'Best First'.
Re: Re: Strings & Scalar Context
by crazysniffable (Acolyte) on Sep 08, 2001 at 01:02 UTC
    So why '0' instead of undefined ('') in the same-as instance?
      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

        (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?