Hi,

I've recently found a bit of code that would be a good candidate to make use of the goto &sub form of the goto command (the one that AUTOLOAD uses), with the minor problem being that it is one level down the stack from what I want to replace.

For example:

sub do_something { my $param = shift; my $info = get_info($param); # more things happen do_something_else($param, $info); } sub get_info { my $param = shift; my $info; if($param eq 'option 1') { $info = 'blah'; } elsif($param eq 'option 2') { do_something_that_might_fail($param) #POINT A $info = 'foo'; } else { $info = 'bar'' } return $info; }

do_something() is called at some point, and then it descends into get_info(). If $param is 'option 2' then a function is called which might fail (at POINT A) - if this fails I'd like to replace the currently running do_something('option 2') with do_something('option 1').

I can replace get_info('option 2') with get_info('option 1') (by setting @_ appropriately and then calling goto &get_info; after POINT A), which will return the $info that I want it to, but when do_something then calls do_something_else it will still be using its original version of $param - 'option 2'.

Is there some way of replacing the caller of the currently running frame of reference with some other function in a similar way to how goto &sub replaces the current running function (without diving too far into the magic internals of perl)?

I'm well aware that for the current problem I'm working on it would be an easy solution, but not necessarily a good one - the current situation may be fixed easily, but if get_info is ever called by any other function things get Sub-Optimal quickly - I just had my curiousity piqued by the potential that may exist.

Thanks for reading,

Prowler
 - Spelling is a demanding task that requies you full attention.


In reply to goto &sub up the stack by prowler

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.