On Tue, 4 Jul 2006, John W. Krahn wrote:


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

Thanks. The problem was solved following one of the suggestions of Shawn
Corey. By mistake, I didn't send my reply to the list, as it should be.
Here it goes, in case it's usefull to someone else.

Jorge


On Tue, 4 Jul 2006, Mr. Shawn H. Corey wrote:


1. Put the call to myroutine in an eval. A die or exit inside an eval
will terminate the eval but not the script. See `perldoc -f eval` for
details.

2. Set a global flag inside abortmyroutine and periodically check for it
in myroutine.

"1" would be somewhat messy, as I wanted to enable CTRL-D only through a
part of myroutine.
"2" works like a charm. Actually, the  flag doesn't need to be global:
        my $abort=0;
        $SIG{'INT'}=sub{
                $SIG{'INT'}='IGNORE';
                $abort=1;
        };
        while(<something>){
                return if $abort;
                # do your job...
        }

Thank you.


--
Jorge Almeida

--
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