in reply to An example of programming by contract

Well, in response to
sub validate_integer      { 1 } # how do you do this?

...you could do...
sub validate_integer {$_[0] == int($_[0])}

I assume, of course, that by "validate integer" you meant to check if the number was an integer.

Quinn Slack
perl -e 's ssfhjok qupyrqs&&tr sfjkohpyuqrspitnrapj"hs&&eval&&s&&&'

Replies are listed 'Best First'.
Re (tilly) 2: An example of programming by contract
by tilly (Archbishop) on Nov 26, 2001 at 18:01 UTC
    Good try, but:
    die "Gotcha!" if validate_integer("not an integer");
    Personally I either wouldn't have the test, or else I would make the test be an RE pattern. eg:
    sub is_integer { $_[0] =~ /^-?\d+\z/; }