in reply to Re: How to implement a timer in perl?
in thread How to implement a timer in perl?

This is a simple example for a Tk based Timeout dialog (timeout: 5 seconds):

#script
use strict; use warnings; use lib qw(.); use Data::Dumper; use TimeOutDialog; my $x; TimeOutDialog::ask(\$x); if ( defined ($x) ) { print "*$x*"; } else { print "timeout\n"; }
#dialog module

package TimeOutDialog; use Tk; sub ask { my $mw = MainWindow->new(); my $target = shift; my $label = $mw->Label ( -text => "Please anwer my question:" )-> +pack; my $text = $mw->Entry->pack; my $button = $mw->Button ( -text => 'confirm', -command => sub { $$target = $text->get(); $mw->destroy; }, )->pack; my $id = $mw->after ( 5000, sub { $$target = undef; $mw->destroy; } ); MainLoop; } 1;


holli, /regexed monk/