Jorge Almeida wrote:
> I want to use CTRL-C to abort execution of a routine (but not of the
> main program). Something like this:
> 
>     # main program
>     $SIG{'INT'}='IGNORE';
>     (...)
>     &myroutine()
>     (...)
>     sub myroutine{
>         # do something
>         (...)
>         $SIG{'INT'}=&abortmyroutine();
>         # do some time consuming stuff...
>         (...)
>         $SIG{'INT'}='IGNORE';
>         (...)
>         return 1;
>         sub abortmyroutine{
>             # do some cleaning...
>             (...)
>             $SIG{'INT'}='IGNORE';
>             # return from myroutine into main program
>             (??????????????)
>         }
>     }
> 
> Pressing CTRL-C executes abortmyroutine(), but what can the latter do to
> exit myroutine? Putting exit in place of (??????????????) would exit the
> program, which is not what I want. Is this possible?

You could try something like this (UNTESTED):

# main program
$SIG{ INT } = 'IGNORE';

sub abortmyroutine {
    $SIG{ INT } = 'IGNORE';
    # do some cleaning...
    {...}
}

{...}
myroutine();
{...}

sub myroutine {
    # do something
    {...}
    $SIG{ INT } = sub { goto &abortmyroutine };
    # do some time consuming stuff...
    {...}
    $SIG{ INT } = 'IGNORE';
    {...}
    return 1;
}



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to