You can always test for results and return an undef on failure, which will make both of your last examples work.

You might want to consider handling as much of the error in the sub itself as possible, that is, your first example may as well do the if-then work inside the sub so that you don't have to write handlers for it every time you call the sub. The main thing you'd want to have in your calling block is logic to protect the rest of the block from a failure in the sub... but the warning should be issued from the place where it occurred if at all possible.

In reply to (ichimunki) Re: Idomatic Handling of Subroutine Error by ichimunki
in thread Idomatic Handling of Subroutine Error by dvergin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":