in reply to Re^3: How do I use a block as an ‘or’ clause instead of a simple die?
in thread How do I use a block as an ‘or’ clause instead of a simple die?

In Perl, false values are customarily used for errors (and not just for builtins).
  • Comment on Re^4: How do I use a block as an ‘or’ clause instead of a simple die?

Replies are listed 'Best First'.
Re^5: How do I use a block as an ‘or’ clause instead of a simple die?
by Marshall (Canon) on Apr 18, 2009 at 22:20 UTC
    The part that was strange was the negative return value. Anyway, I showed how to keep track of the re-tries, etc which was the main point.

    In general, Perl does like C. There is some historical weirdness that we just have to live with. In Perl a .pm module has to return non-zero when "all is ok" (usually just by last line of 1;), but a Perl program returns (0) to the O/S if it works (*nix or Windoze). Perl should return a positive error code if it abends. This is strange and inconsistent and I'm not saying that it isn't.

    For the most part the Perl functions and C functions do what you expect in terms of true/false. In C there is weirdness with EOF, that's -1. So, yes there are funcs that return negative values for "true". In Perl most of these weirdo cases have been solved and I'm not saying that they aren't. I've never tested a loop for an EOF value in Perl... the subject just doesn't come up.

    I am saying that returning a negative number for an error code is a strange thing to do. If non-zero means a error code, then a positive number is far better than a negative number. For a T/F value, return either 0 or a positive number.