in reply to Subroutine to indicate error condition

If you mean that some Perl function in module A (in say FileA.pm or main program) calls some sub, funcB() in Perl module B(in FileB.pm or even within main program module) and this funcB() does an exit(1)...There is nothing to be "done" about it, exit(x) returns a status code to the OS and the Perl program stops. Your funcA() will never see this exit(1) value.

It sounds to me like you should replace say "exit(1);" with die "some error message";. "die" prints an error message to STDERR and then the Perl program stops. If the "die" statement's string does not end in a \n, then Perl will report module and line number when "death occured". Normally this is of no interest to the user if the error message is good enough. But sounds like this tid-bit will help you debug a problem (extra info good for you).

The "normal" convention for a program to exit when it completes successfully is exit(0) or exit(with a non zero value) if program "bombed". That value (8 bits) is reported to the shell that invoked the program. I don't think that you want to mess around with starting a shell program that starts your Perl script and checks the return code.

Instead of exit(1), in Perl use: die "some error". Throwing exceptions has to do with OO stuff and OO is probably not what you have here in the legacy code. Do a search for the exit() lines and replace with 'die "error msg"' lines.

  • Comment on Re: Subroutine to indicate error condition