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? >
Yes, two ways. 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. -- __END__ Just my 0.00000002 million dollars worth, --- Shawn "For the things we have to learn before we can do them, we learn by doing them." Aristotle * Perl tutorials at http://perlmonks.org/?node=Tutorials * A searchable perldoc is at http://perldoc.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>