in reply to Parameter validation for numeric function arguments?

Some factors to consider:

Should this function validate its input and warn/fail if a non-numeric value is provided? The built-in functions do not do this

Actually, they do.

>perl -wE"say sin('foo')" Argument "foo" isn't numeric in sin at -e line 1. 0 >perl -wE"say cos('3.1415bar')" Argument "3.1415bar" isn't numeric in cos at -e line 1. -0.999999995707656

Replies are listed 'Best First'.
Re^2: Parameter validation for numeric function arguments?
by janert (Sexton) on Aug 24, 2011 at 22:17 UTC

    Thanks to everyone who has chimed in.

    What I am taking away here is this:

    • We all agree that input validation is desirable...
    • ... but the way to do it is via warnings, which can be switched on/off using use warnings; or the -w flag. (Inspect the $^W variable in your code to find out.)

    Thanks again, this was helpful.