in reply to Interrupting a loop
Also, Tk already incorporates a loop: the MainLoop. Looping over short lists is probably OK, but introducing loops that might take a long time to iterate or have a high number of iterations is wrong, you should use Tk->repeat or Tk->after instead, see Tk::after.
#!/usr/bin/perl use warnings; use strict; use Tk; sub periodically { warn "Testing the file existence...\n"; } my $mw = MainWindow->new(-title => 'Test'); my $repeat = $mw->repeat(1000, \&periodically); $mw->bind('<Control-c>', sub { $mw->afterCancel($repeat) }); MainLoop();
Update: Added the example.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Interrupting a loop
by etj (Priest) on Jul 28, 2024 at 13:43 UTC | |
|
Re^2: Interrupting a loop
by cavac (Prior) on Jul 29, 2024 at 05:09 UTC | |
|
Re^2: Interrupting a loop
by merrymonk (Hermit) on Jul 28, 2024 at 13:42 UTC | |
by merrymonk (Hermit) on Jul 30, 2024 at 10:32 UTC | |
by jdporter (Paladin) on Jul 28, 2024 at 14:08 UTC |