Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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


In reply to Re: Multiple Rows by mtmcc
in thread Multiple Rows by PilotinControl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2024-04-19 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found