You should use what you think is best. Probably the most
common methods are: returning a special value (undefined,
0, empty string, empty list, -1, MAX_INT) or performing
a
die. I fancy the latter, but I use the former
often as well. The former has two drawbacks: you can't return
a value that indicates "error" if there's no error, and you
either have to reserve an range of special values, or you
can't signal what went wrong, other than scribbling the reason
away somewhere (compare
open returning false,
and using
$! to indicate the reason).
Throwing an exception (die) doesn't suffer from
this. You don't "lose" possible return values, and you can
do the "return" and reason all at once, just die
with a reason. The caller still needs to do two things,
using eval and checking $@, but
the caller already needed to do two things.
But please use whatever you are most comfortable with.
And that might vary from project to project. Or even from
method to method.
Abigail