and then you can read from STDIN and if there is nothing waiting your script will continue. Note that this doesn't work on Win32. I have created the same functionality in the past using a watchdog file:
my $watchdog = "./watchdog.@{[time]}.$$"; open WATCHDOG, ">$watchdog" or die "Cannot open $watchdog for output +: $!\n"; print WATCHDOG "This file may safely be deleted\n"; close WATCHDOG; while( $universe->evolve ) { if( !(++$iters % 100_000) ) { last unless -f $watchdog; } # do some more stuff } do_logging(); unlink $watchdog;
Once your script is churning away, all you have to do is to find some way of deleting the file you created at the top of the script. Kill it, and your script can close down doing whatever housekeeping needs to be done.
In the example, I show that the test be performed once every x iterations. For performance reasons, you don't really want to be statting the disk on every iteration. Tune this value to get the reactivity you require.
I quite like this solution, as you don't need to install another module, it's eminently portable and other processes can kill the execution if need be.
--In reply to Re: keyboard input during runtime...
by grinder
in thread keyboard input during runtime...
by Shadowfax
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |