Theres some way to these tests are shown in real time in my Text/Scrolled?

You have a couple of problems in the way you setup your gotest sub. First, never use a sleep() or an intensive loop in a GUI, it will block the Tk eventloop.

You probably can make your hack work by printing to the Text widget, instead of the console, and do a $mw->update immediately. Like this:(untested)

if ( @$ref){ $textsc->insert('end',"Lets see Wich Ips are ON...\n"); @ipsproxy = map("$_->{ip}", @$ref); $p = Net::Ping->new("icmp"); $p->bind('187.78.223.205 '); @validos = (''); foreach $aaa (@ipsproxy) { print "$aaa is "; $textsc->insert('end', "$aaa is "); $mw->update; # etc etc for all your print statements
But you should redesign your code to account for the fact that Tk has an eventloop. Here are a few examples from previous code posted here.
ping your local net
#!/usr/bin/perl use warnings; use strict; use Tk; use Net::Ping; my ( $ip, $hostname, $mw, $hostfile, $int, $frame, $stat, %list, $body + ); # Process arguements while ( @ARGV and $ARGV[0] =~ /^-/ ) { $_ = shift; last if /^--$/; if (/^-f(.*)/) { $hostfile = $1 } elsif (/^-i(.*)/) { $int = $1 } else { usage(); } } # Set default values if no arguments were supplied unless ( defined($hostfile) ) { $hostfile = "/etc/hosts" } unless ( defined($int) ) { $int = "30" } open HOSTFILE, "< $hostfile" or die "can't read $hostfile: $!"; # Create a hash of the hostfile; omitting comments, localhost, and # blank lines while (<HOSTFILE>) { s/#.*//; # remove any comments next if /^\s+$/; next if /^127\./; ( $ip, $hostname ) = split; $list{$hostname}{hostname} = $hostname; $list{$hostname}{ip} = $ip; my ( $status, $color, $p ); $p = Net::Ping->new("icmp"); if ( $p->ping( $ip, 1 ) ) { $list{$hostname}{status} = "UP"; $list{$hostname}{color} = "green"; } else { $list{$hostname}{status} = "DOWN"; $list{$hostname}{color} = "red"; } } $mw = MainWindow->new(); $mw->title("NetMon Tool"); $mw->geometry('+10+10'); $mw->configure( -background => "black" ); # create topmenu menu my $tm = $mw->Frame( -relief => 'groove', -borderwidth => 3, -background => 'white', )->pack( -side => 'top', -fill => 'x' ); # create frames $body = $mw->Frame( -background => "black", )->pack( -side => 'top', -fill => 'x' ); sub pingagain { # Ping each host once and label UP or DOWN my ( $host, $p ); $p = Net::Ping->new("icmp"); foreach $host ( keys %list ) { if ( $p->ping( $list{$host}{ip}, 1 ) ) { $list{$host}{status} = "UP"; $list{$hostname}{color} = "green"; $stat->configure(-background => 'green'); } else { $list{$host}{status} = "DOWN"; $list{$hostname}{color} = "red"; $stat->configure(-background => 'red'); } } textdisp(); } sub textdisp { my ($host); # system("clear"); foreach $host ( keys %list ) { print "$list{$host}{hostname} \t"; print "$list{$host}{ip}\t"; print "$list{$host}{status}\n"; } } sub usage { print STDERR <<"_EOT_"; Usage: netmon <options> Where options are: -i<interval> : The interval, in seconds, at which netmon should ping hosts Default: 30 -f<filename> : The configuration file containing space delimited IP addresses and hostnames to be monitored. Default: /etc/hosts Example: netmon -i5 -f/tmp/myhostfile _EOT_ exit(1); } sub statdisp { my ($host); foreach $host ( keys %list ) { $frame = $body->Frame( -background => "$list{$host}{color}", ) +->pack( -side => 'top', -fill => 'x' ); $stat = $frame->Label( -background => "$list{$host}{color}" )- +>pack( -padx => 12, -side => "left", -expand => 1, -fill => "x" ); $stat->configure( -text => $list{$host}{hostname} ); $stat = $frame->Label( -background => "$list{$host}{color}" )- +>pack( -padx => 16, -side => "left", -expand => 1, -fill => "x" ); $stat->configure( -text => $list{$host}{ip} ); $stat = $frame->Label( -background => "$list{$host}{color}" )- +>pack( -padx => 4, -side => "right", ); $stat->configure( -text => "$list{$host}{status}" ); } } textdisp(); statdisp(); $mw->repeat( 1000, \&pingagain ); $mw->update; MainLoop();
and another example
#!/usr/bin/perl -w use Tk; use Tk::Menubar; use Cwd; require Tk::Dialog; require Tk::ROText; use strict; #------------------------------------------------------------------- # Main Window Setup and configuration #------------------------------------------------------------------- my $MW = MainWindow->new(); $MW->title("TESTGUI "); #------------------------------------------------------------------- # Menubar #------------------------------------------------------------------- my $menubar = $MW->Menubar; #------------------------------------------------------------------- # Menubuttons #------------------------------------------------------------------- my $f = $menubar->Menubutton( -text => 'File', -underline => 0 ); my $run = $menubar->Menubutton( -text => 'Run', -underline => 0 ); #------------------------------------------------------------------- # Menu sub-buttons #------------------------------------------------------------------- $f->command( -label => 'Close', -command => sub { exit }, -underline = +> 0 ); $run->command( -label => 'RUN PING COMMAND', -command => [ \&run_pc ] +); #------------------------------------------------------------------- # Frame 1 - INPUT VARIABLES FRAME (Main body frame) #------------------------------------------------------------------- my $N = 1; my $frm1 = $MW->Frame; my $tl1 = $frm1->Label( -text => "NOT IMPORTANT, JUST USED SPACE FOR SETTING VARIABLES", -relief => 'raised', -background => "gray" )->grid( -row => 0, -column => 0, -sticky => 'nsew', -columnspan => 2 ); $frm1->pack; MainLoop; #------------------------------------------------------------------- # Run PC subroutine #------------------------------------------------------------------- sub run_pc { my $pcwin = new MainWindow( -title => "PC OUTPUT LOG WINDOW" ); `ping -c 20 localhost > pc_output.log &`; my $pidpc = open( RUNCOMMANDD, "tail -f pc_output.log |" ) || die $!; my $outputtext = $pcwin->Scrolled( "Text", -scrollbars => "e", -width => 80, -height => 45, -wrap => "word" )->pack(); my $quitbutn = $pcwin->Button( -text => "Close", -command => sub { close(RUNCOMMANDD); kill 'TERM', $pidpc; `echo "bye" >> pc_output.log`; $pcwin->fileevent( \*RUNCOMMANDD, 'readable' => '' ); $pcwin->destroy; } )->pack(); $pcwin->fileevent( \*RUNCOMMANDD, 'readable', [ \&fill_text_widget, $outputtext ] ); } sub fill_text_widget { my ($widgett) = @_; my ( $stat, $data ); $stat = sysread( RUNCOMMANDD, $data, 4096 ); die "sysread error: $!" unless defined $stat; $widgett->insert( 'end', $data ); $widgett->yview('end'); }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: TK, insert and foreach by zentara
in thread TK, insert and foreach by papaismurf

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.