Hacker News new | ask | show | jobs
by tyingq 2037 days ago
Is there a reason returning undefined instead of true in those cases (string doesn't look like a number) would be worse?
1 comments

Very few functions in Perl does that. It will emit a warning instead.

As to why that is, perhaps someone with more Perl knowledge can chime in. I suspect it has to do with undef being inconvenient for signalling failure, since its evaluation will be context dependent (an array of undef is true but a numeric undef is false).

Type conversion is built into the language at a fundamental level. Languages that borrows the syntax but not the type model can be confusing in cases, but Perl is pretty consistent once you get the basics.