So,
Does perl have any commands that allow you to forcefully stop a subroutine? I know I can stop it from within using exit, but it would be easier if I could stop it from without.
Unless you're dealing with threads or forked processing, your question doesn't make any sense. Most perl programs are sequential, as in only one sub has active control at any given time. Can you clarify the context in which you are asking the question?
Perl Tk. It's possible to push a button and start a subroutine while another is going if one has used $mw->update in the first.
Part of my program searches for files. As it finds them, it adds them to a list and performs $mw->update; As the list is populating, a user can click on the file and get more information on it in the same window. (The text box is cleared first with a delete(1.0,'end') However, right after the information is displayed, more search results appear below as the search continues. If enough results appear, the information is lost as the window scrolls.
I know I could disallow the user to click until after the search finishes, but since the search finds most recent files first, I think the user would be waiting a long time for the search to find files he/she doesn't care about.
Even with Tk, Perl is still executed sequentially. When the code for your button executes, Perl is only running that code, which is why the rest of the GUI will freeze unless you keep running $mw->update.
So a logical way to look at it is...
1. The code for the button is running.
2. You should be able to stop it from running via the GUI.
3. The GUI is only open to receive events when you call update()
So you could do something like, say, have $cancel be a variable and each time you call update in the sub:
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.