You're using words like 'subroutine' but you seem to imply that you are returning your values via exit and $@, which tells me you're evaling code instead of calling it as a straightforward subroutine.

If this is the case, your 'exit' return value isn't going to magically appear in $@. You'll need to examine the value of $? if you want to do it that way (but be warned, the value of this will need to be << 8'd to get at the number you passed to exit).

sub some_sub { ... return 5; # not 'exit', as this terminates the script } $returned = &some_sub; # 5 eval "exit(&some_sub)"; # exits block with return value of 5 $returned = $? << 8; # 5
Obviously, the first method is far more efficient and practical than evaluating code. I hope I'm not misunderstanding what you're doing here. You may be interested in perlsub and documentation for eval and perlvar (for $? and $@).

In reply to Re: return codes from embedded subroutines by Fastolfe
in thread return codes from embedded subroutines by oakley

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.