fileevent worked for me. Just populate the widget from a fileevent handler:
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
my $mw = 'MainWindow'->new(-title => 'nmap');
my $b1 = $mw->Button(-text => 'Go', -command => \&go)->pack;
my $b2 = $mw->Button(-text => 'Exit', -command => \&Tk::exit)->pack;
my $text = $mw->Scrolled('Text', -scrollbars => 'e')->pack;
MainLoop();
sub go {
open my $nmap, '-|', 'nmap -A localhost' or die $!;
$text->fileevent($nmap, 'readable', sub {
$text->insert(end => scalar <$nmap>);
});
}
BTW, no need for sub {&go} etc. Lexical filehandles and 3-argument form of open exist for pipes, too.
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord
}map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,