I have a sub routine that sends an email and relies on a SMTP argument when called. If the SMTP isn't specified the call will obviously fail, however the logging line that occurs after the sub routine call will get skipped.

How do i gracefully handle the sub routine failure and allow the program to move to the next line, or at least test it's success/failure to execute?

most functions/subs return a 0 or 1 to indicate failure or success respectively. You can use that to make the function/sub call a condition:

A caveat, without an explicit return statement, a Perl sub will return the value returned from the last statement it executed, which may not be what you exepect when it's evaluated in boolean context. If the sending of the email failed, but the last statement executed was, for example, a print statement, then the sub will return a true value.

most functions/subs return a 0 or 1 to indicate failure or success respectively. You can use that to make the function/sub call a condition:

A caveat, without an explicit return statement, a Perl sub will return the value returned from the last statement it executed, which may not be what you exepect when it's evaluated in boolean context. If the sending of the email failed, but the last statement executed was, for example, a print statement, then the sub will return a true value.

The first piece worked perfect and passed everything through. That was my mistake, I should've realized just attached a variable to the $smtp->dataend(); would give it a true/false kind of thing.

The second piece is indeed much simpler, but it doesn't seem to work in windows with the default installation of the ActivePerl, which is where this will run.

Let me know if I'm not doing something right.

Thanks again!

While I agree with Fish about MIME::Lite, using Net::SMTP is OK. If your code is now working (thanks for the assist Fish) then you can leave it as is unless you really want to try MIME::Lite. -------------------------------------------------