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.


DWIM is Perl's answer to Gödel

In reply to Re: Return Question in Subroutine by GrandFather
in thread Return Question in Subroutine by Anonymous Monk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.