http://www.perlmonks.org?node_id=103534

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!