in reply to Continuations in Perl - Returning to an arbitrary level up the call stack

doesnt sound like you need continuations, I think a simple goto is enough, just put a label at the target position.

update

my $i=0; target(); sub target { rec(); TARGET: print "END"; } sub rec { $i++; print "IN $i\n"; goto TARGET if ($i>5); # return skipping multiple levels rec(); # 6 levels recursive call print "OUT $i\n"; # never reached }
out...
IN 1 IN 2 IN 3 IN 4 IN 5 IN 6 END

Cheers Rolf

( addicted to the Perl Programming Language)

update

added comments

Replies are listed 'Best First'.
Re^2: Continuations in Perl - Returning to an arbitrary level up the call stack
by unlinker (Monk) on May 18, 2013 at 20:50 UTC

    Unfortunately, the functions up the call stack are modules that I dont control. These modules call my function and I dont want to return to the calling module but one level higher up the stack.

    Thanks for the suggestion though. I am currently looking at Continuation::Escape for a possible solution

      > I dont want to return to the calling module but one level higher up the stack.

      Thats where you have to place the target label.

      Anyway I doubt that your approach is reasonable, sorry! Maybe a XY problem?

      Cheers Rolf

      ( addicted to the Perl Programming Language)