in reply to Re: Re: Re: Strings & Scalar Context
in thread Strings & Scalar Context

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

  • Comment on Re: Re: Re: Re: Strings & Scalar Context

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Strings & Scalar Context
by John M. Dlugosz (Monsignor) on Sep 08, 2001 at 01:47 UTC
    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