merrymonk has asked for the wisdom of the Perl Monks concerning the following question:
I am having trouble with interrupting Perl as it processes a loop with a ‘sleep’ in it.
I am using Perl on a Windows 11 pc.
The included code runs a loop. At the start of the loop is ${INT} which sets a sub to be used if CNTRL-C is used. This sub simply sets the variable $loop_test to zero so that the loop ends.
This test Perl works. However, when I use this is the ‘production’ application, where a sub is also called (this tests if a file has recently being store and then acts on this information) CNTRL-C does not work.
Has any Monk a suggestion as to how this can be made to work?
I am using Perl Tk and could have a button which when used has the effect of calling the sub to set a variable to end the loop
My attempts to do this have failed because the button fails to respond.
I seem to remember (it is a few years since I have written any Perl Tk code) that there is some property that can be assigned to a button so that it would work in these circumstances.
However, my searches for this have failed.
Can any Monk point me it the right direction?
I am using Perl on a Windows 11 pc.
The included code runs a loop. At the start of the loop is ${INT} which sets a sub to be used if CNTRL-C is used. This sub simply sets the variable $loop_test to zero so that the loop ends.
This test Perl works. However, when I use this is the ‘production’ application, where a sub is also called (this tests if a file has recently being store and then acts on this information) CNTRL-C does not work.
Has any Monk a suggestion as to how this can be made to work?
use strict; use warnings; my ($loop_test, $cou); $loop_test = 1; $cou = 0; while($loop_test > 0) { # something which the lets the user set $loop#_tes to 0 $SIG{INT} = \&tsktsk; sleep(5); $cou = $cou +1; print "end sleep - count $cou\n"; # sub to do something - for exmaple see if a files mod time has change +d } print "\nEND\n"; sub tsktsk{ $loop_test = 0; print "[tsktsk] called\n"; }
I am using Perl Tk and could have a button which when used has the effect of calling the sub to set a variable to end the loop
My attempts to do this have failed because the button fails to respond.
I seem to remember (it is a few years since I have written any Perl Tk code) that there is some property that can be assigned to a button so that it would work in these circumstances.
However, my searches for this have failed.
Can any Monk point me it the right direction?
Back to
Seekers of Perl Wisdom