First, it's worth using strict and warnings.
Second, when you configure the text of the label in a loop, you literally do just that, ie you set the text of the label to the current value you assign to it.
If you want a multiline label, I'd join the individual lines together into a single string before printing it, like this:
#!/usr/bin/perl
use Tk;
use strict;
use warnings;
my $window = MainWindow->new;
$window -> geometry("100x200");
$window->title("Host Report");
my $labs = $window->Label(-text => "Results", -wraplength => 100)->pac
+k(-side => 'bottom');
#$window->Entry(-textvariable => \$hdb )->pack;
$window->Button(-text => "Go", -command => \&host )->pack;
$window->Button(-text => "Quit", -command => \&stop )->pack;
MainLoop;
sub host {
my @message;
#open (FH,"host.txt");
my @lines = <DATA>;
#close FH;
foreach my $hdb2 (@lines) {
my @field = split(':',$hdb2);
#if ($field[0] =~ /(?<![\w-])$hdb(?![\w-])/i) {
push (@message, "$field[0] $field[1] $field[2]");
#}
}
my $messageString = join ('', @message);
$labs->configure(-text =>"$messageString");
}
sub stop{
exit;
}
__DATA__
these: lines
are: the: lines
that: you
are: looking: at
Alternatively, you could use a widget other than a label, maybe something like this:
!/usr/bin/perl
use strict;
use warnings;
use Tk;
use Tk::ROText;
my $hdb;
my $window = MainWindow->new;
$window->title("Host Report");
my $labs = $window->Scrolled('ROText')->pack(-side => 'bottom');
$labs -> Insert ("Results\n\n");
$window->Entry(-textvariable => \$hdb )->pack;
$window->Button(-text => "Go", -command => \&host )->pack;
$window->Button(-text => "Quit", -command => \&stop )->pack;
MainLoop;
sub host {
#open (FH, "<", "host.txt");
my @lines = <DATA>;
print STDERR "@lines\n\n";
#close FH;
foreach my $hdb2 (@lines) {
my @field = split(':',$hdb2);
#if ($field[0] =~ /(?<![\w-])$hdb(?![\w-])/i) {
$labs->Insert("$field[0] $field[1] $field[2]");
#}
}
}
sub stop{
exit;
}
__DATA__
these: lines
are: the: lines
that: you
are: looking: at
I hope that's helpful