A called routine should not make any assumptions about the routine that called it, or the routine that called that routine, etc. As stated in the base node, if you really want to do this, the proper way would be some kind of exception signalling mechanism.

Here's your little snippet.

sub bar { $foo = askFor( title => 'Name:' ); return undef if not defined $foo; $baz = askFor( title => 'Cigarettes:' ); return undef if not defined $baz; }

Now, I doubt very much that the whole point of this subroutine was to ask for a couple of pieces of information and throw them away. So, there would probably be some code after the second return that actually does something with $foo and $baz.

Suppose there were a couple of other places in your program that needed to ask for these pieces of information. Instead of having those four lines all over your code, you decide to refactor and make a separate subroutine called getFooAndBaz() to ask for those values. Does askFor() now have to jump three call frames? Why should it care what path was taken to call it? How does that affect the procedure that calls askFor() directly?

--- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';

In reply to Re: Re: Double your return!!!! by pfaut
in thread Double your return!!!! by bsb

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.