Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

How can a user pause a running script?

by tshabet (Beadle)
on Aug 09, 2001 at 21:56 UTC ( #103534=perlquestion: print w/replies, xml ) Need Help??
tshabet has asked for the wisdom of the Perl Monks concerning the following question:

OK, this seems like a problem that someone else must have run into before, so I'm looking for advice from the fantastic Monks.
I'm running a script that uses Text::Balanced to parse blocks of code with balanced braces. The script itself runs great, but since not everyone using this script will be as careful as I am (heh heh) I'm building in some error handling and diagnosis etc. One feature that I have is sort of combo looking cool/actually helpful. Basically, the pertinent piece of code looks like this:
while($next = (extract_bracketed($text, '{}', '[^{}]*' ))[0]) { $holder = $next; $next =~ s/\{([\w|-]*)(.*)\}/<$1>$2<\/$1>/osi; $text =~ s/$holder/$next/sgi; print "Sync check \#$counter\n"; print "$next\n"; $counter++; }
OK, fair enough. The code works nicely, spits out a little counter number and displays the code block currently being processed. So I found this pretty handy if/when a piece of sample input went into an infinite loop or something, I could actually see it not changing. Now what I'd like to offer other users of this code is the ability to stop/start the code while in the loop above, so that they could actually stop the output, look at the half processed block, then start it again. I figure this would be handy for folks trying to understand the way the tool works, plus handy for people trying to debug a problem with the way my code and their input interact. So how to best implement this? I've looked at the sleep() function, which could be cool. Should I just put a sleep(10) in an if(the foo key is struck) type of statement within the while loop? If this isn't practical or possible without big problems for the code, no biggy. I'm just wondering if anyone has already dealt with this problem in their own work and found a neat solution. Thanks Monks!

Replies are listed 'Best First'.
(jeffa) Re: How can a user pause a running script?
by jeffa (Bishop) on Aug 09, 2001 at 22:08 UTC
    How about simply using the diamond operator to wait for user input?
    my $dummy; while (..) { ... $counter++; print $text; $dummy = <>; }
Re: How can a user pause a running script?
by bikeNomad (Priest) on Aug 09, 2001 at 22:09 UTC
    What's wrong with hitting ctrl-S to stop the output and ctrl-Q to start the output, as we do with most other programs?

      Personally I hate doing that, cos you hit ctrl+s to freeze the screen, then when you hit ctrl+q again your window gets flooded with stuff if there's more than one page meaning you miss all the other data.

        That's why I prefer ctrl-Z, as it actually stops the running of the program and gives back the command prompt. Since you get the command prompt back, it seems like a better solution anyway; the user can look at the output files and then deside to "fg" the program to let it continue.


Re: How can a user pause a running script?
by scain (Curate) on Aug 09, 2001 at 22:05 UTC
    Is this on a unix-type box? If so, cntl-Z will stop operation and entering "fg" will start it again ("bg" will start it again in the background).


Re: How can a user pause a running script?
by tshabet (Beadle) on Aug 09, 2001 at 22:41 UTC
    Have you ever had one of those days when you should have stayed in bed? Here I am, a guy using Unix variants just about every day for the last, oh, 6 years......and I kid you not, using ctrl-s and ctrl-q NEVER occured to me. Boy.... Yes, this is to be run on a unix box, so that solution works perfectly  <slaps forehead>
    Sorry to waste your time guys, I feel pretty dumb right now. I should probably take a nap. My apologies for my oversight :-(

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://103534]
Approved by root
Tux waves back

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2018-02-21 12:52 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (279 votes). Check out past polls.