Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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?
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?

In reply to Interrupting a loop by merrymonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others browsing the Monastery: (6)
    As of 2024-10-03 10:43 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      The PerlMonks site front end has:





      Results (42 votes). Check out past polls.

      Notices?
      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.