in reply to Return Question in Subroutine
You need to consider what the alternatives are and how the calling code might handle them.
One way to handle it is to die. The calling code doesn't need to do anything special, but it is very likely that you don't want to kill the program at that point. You can set up a handler so that the die is caught and managed in some fashion, but that is way outside of anything we can advise on without knowing a lot more about what your code is doing.
You could return undef which can be detected as a special case and handled by the calling code. If it is not handled, but you have warnings turned on (you do use warnings; don't you?) then chances are the program will issue warnings when the returned value is undef and subsequently used.
Or you can use the current code which again can be detected as a special case by the calling code, but will not generate warnings in most code.
However, without knowing what the calling code is doing and how it might handle errors, it is rather hard to give a good definitive answer.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Return Question in Subroutine
by Anonymous Monk on Apr 28, 2006 at 13:05 UTC | |
by GrandFather (Saint) on Apr 28, 2006 at 13:18 UTC |