use strict; use warnings; use IO::Handle; open(WRITE, ">>C:\\File\\test.dat"); WRITE->autoflush(1); my $num = 1; while(1) { print "$num\n"; print WRITE "Some new text $num\n"; # using sleep to try and emulate the speed of the actual program sleep 1; $num ++; } close WRITE; #### use strict; use warnings; use Tk; use File::Tail; my $mw; my $name = 'C:\File\test.dat'; my $message; init_ui(); MainLoop; sub init_ui { $mw = MainWindow->new( -title => 'Test' ); $mw->resizable( 0, 0 ); my $top = $mw->Frame( )->pack( -side => 'top', -expand => '1', -fill => 'both' ); my $button1 = $top->Button( -text => "Listen", -width => '10', -command => sub { file_listen(); } )->pack( -side => 'left'); my $button2 = $top->Button( -text => "Button2", -width => '10' )->pack( -side => 'left'); my $bottom = $mw->Frame( )->pack( -side => 'top', -expand => '1', -fill => 'both' ); my $status = $bottom->Label( -textvariable => \$message, )->pack( -side => 'left' ); } sub file_listen { $message = 'Listening ... '; $mw->update; my $file=File::Tail->new(name=>$name, nowait=>1); while (defined(my $line=$file->read)) { if ($line =~ /\d+/) { chomp($line); $message = $line; } $mw->update; } }