Monks,

I am working on an application that has 2 text boxes.

one gathers data: $config_text
the other shows the results: $results_text

When a button is pressed the data from that test box is retrieved and stored in an array. After some checks all the data is submitted to the proper sub routine and in each one Net::Telnet::Cisco is called and executes it's foreach loop roughly 20-100 times. Inside the foreach loop I call $results_text->insert('end', "update");. The problem is I won't see the text until the foreach loop has completed all of its runs.

I tried using the after() listed in the following post, but had no luck.

http://www.perlmonks.org/index.pl?node_id=65969

However,I could have implemented it wrong?

Thanks,
Any help or suggestions is appreciated, full source:

#!/usr/bin/perl #################################### #Date: 5/16/2003 # #Author: Jason Riedel # #Title: Cisco Configuration Changer# ###################################################################### +# #Purpose: To globally change cisco configuration in a simple easy GUI. +# ###################################################################### +# use strict; use DBI; use Net::Telnet::Cisco; use Tk; require Tk::MesgBox; require Tk::Radiobutton; ####################### # VARIABLES # ####################### use vars qw /@config $radio $ip $routeruser $routerpass/; ########################### # Windows & Widgets # ########################### ########################### my $w = MainWindow->new(); $w->configure(-title => 'Cisco Configuration Changer v1.0', -backgroun +d => 'gray'); $w->geometry('+250+250'); ## Create Window Frame ## my $menu_bar_frm = $w->Frame(-relief=> 'groove', -borderwidth=>3, -bac +kground=>'gray')->pack(-side => 'top', -fill=>'x'); ## Create File Menu ## my $file_button = $menu_bar_frm->Menubutton(-text=> 'File', -underline +=> 0, -background=> 'gray', -activebackground=> 'white', -foreground= +> 'blue')->pack(-side => 'left'); my $file_menu = $file_button->Menu(); ## Create Option Exit ## $file_menu->command(-command => \&end, -label => "Exit", -underline => + 0); $file_button->configure(-menu=>$file_menu); ## Create Help Menu ## my $help_button = $menu_bar_frm->Menubutton(-text=>"Help", -underline +=> 0, -background=> 'gray', -activebackground=> 'white', -foreground= +>'blue')->pack(-side => 'left'); my $help_menu = $help_button->Menu(); ## Create Option About ## $help_menu->command(-command => \&about, -label => "About", -underline + => 0); $help_button->configure(-menu=>$help_menu); ## Create Frames ## my $w_radio_frm = $w->Frame(-relief=> 'groove', -borderwidth=>0, -back +ground=>'gray')->pack(-side => 'top', -fill=>'x'); my $w_login_frm = $w->Frame(-relief=> 'groove', -borderwidth=>0, -back +ground=>'gray')->pack(-side => 'top', -fill=>'x'); my $w_config_frm = $w->Frame(-relief=> 'groove', -borderwidth=>0, -bac +kground=>'gray')->pack(-side => 'left', -fill=>'x'); my $w_results_frm = $w->Frame(-relief=> 'groove', -borderwidth=>0, -ba +ckground=>'gray')->pack(-side => 'left', -fill=>'x'); ## Create Single Label & Entry ## my $single_label = $w_radio_frm->Label(-text => 'Single IP:', -backgro +und => 'gray', -foreground => 'blue')->pack(-side => 'left'); my $single_entry = $w_radio_frm->Entry(-textvariable=> \ $ip)->pack(-s +ide => 'left'); ## Create Radio Buttons ## my $cmts_button = $w_radio_frm->Radiobutton(-text=> 'CMTS\'s', -value= +> 'CMTS\'s', -variable=> \$radio)->pack(-side => 'left'); my $cores_button = $w_radio_frm->Radiobutton(-text=> 'Cores', -value= +> 'Cores', -variable=> \$radio)->pack(-side => 'left'); my $switches_button = $w_radio_frm->Radiobutton(-text=> 'Switches', - +value=> 'Switches', -variable=> \$radio)->pack(-side => 'left'); my $all_button = $w_radio_frm->Radiobutton(-text=> 'All', -value=> 'A +ll', -variable=> \$radio)->pack(-side => 'left'); ## Create Login & Password Label & Entry ## my $user_label = $w_login_frm->Label(-text => 'Username:', -backgroun +d => 'gray', -foreground => 'blue')->pack(-side => 'left'); my $user_entry = $w_login_frm->Entry(-textvariable => \ $routeruser, - +width => '20')->pack(-side => 'left'); my $pass_label = $w_login_frm->Label(-text => 'Password:', -backgroun +d => 'gray', -foreground => 'blue')->pack(-side => 'left'); my $password_entry = $w_login_frm->Entry(-textvariable => \ $routerpas +s, -width => '20', -show => '*')->pack(-side => 'left'); ## Create Entry Box ## my $config_entry = $w_config_frm->Scrolled('Text', -width => '50', -he +ight => '40')->pack(-side => 'left'); ## Create Text Box ## my $results_text = $w_results_frm->Scrolled('Text', -width => '40', -h +eight => '40')->pack(-side => 'right'); ## Create Buttons ## my $config_button = $w_config_frm->Button(-text=>'Config', -background +=>'gray', -command => \ &config)->pack(-side => 'left', -anchor=> 'ce +nter'); ########## # Config # ########## ########## sub config { @config = (); @config = $config_entry->get('1.0', 'end'); #################### # SQL DATA # #################### my $dsn = "DBI:mysqlPP:db:host"; my $dbuser = "dbuser"; my $dbpass = "dbpass"; my $dbh = DBI->connect($dsn,$dbuser,$dbpass) or die ("could not co +nnect to sql"); my $cmts = $dbh->prepare( qq |SELECT system, ip FROM systems WHERE + device="CMTS"| ) or die ("could not connect to sql"); my $core = $dbh->prepare( qq |SELECT system, ip FROM systems WHERE + device="Core"| ) or die ("could not connect to sql"); my $switch = $dbh->prepare( qq |SELECT system, ip FROM systems WHE +RE device="Switch"| ) or die ("could not connect to sql"); if (defined($routeruser) and defined($routerpass)) { if (defined($ip)) { $results_text->delete('1.0', 'end'); $results_text->insert('end', "Running the submitted config +uration for: $ip\n\n"); single(); } elsif ($radio eq "CMTS\'s") { $results_text->delete('1.0', 'end'); $results_text->insert('end', "Running the submitted config +uration for: All CMTS\'s\n\n"); cmtss($cmts); } elsif ($radio eq "Cores") { $results_text->delete('1.0', 'end'); $results_text->insert('end', "Running the submitted config +uration for: All Cores\n\n"); cores($core); } elsif ($radio eq "Switches") { $results_text->delete('1.0', 'end'); $results_text->insert('end', "Running the submitted config +uration for: All Switches\n\n"); switches($switch); } elsif ($radio eq "All") { $results_text->delete('1.0', 'end'); $results_text->insert('end', "Running the submitted config +uration for: All\n\n"); all($cmts, $core, $switch); } } else { $results_text->delete('1.0', 'end'); $results_text->insert('end', "Username and Password were not d +efined and must be to run.\n"); } $ip = undef; } MainLoop; ########## # Single # ########## ########## sub single { eval { my $cisco = Net::Telnet::Cisco->new(Host => $ip); $cisco->login("$routeruser", "$routerpass"); $cisco->cmd( 'terminal length 0' ); $cisco->cmd( 'config t' ); $results_text->insert('end', "$ip - done\n"); foreach my $command (@config) { @config = $cisco->cmd($command); } $cisco->close; }; if ($@) { $results_text->insert('end', "\n$ip Errored: $@\n\n"); } } ########## # CMTS's # ########## ########## sub cmtss { my (%cmts, $system); my $cmts = shift; $cmts->execute(); while (my $row = $cmts->fetchrow_arrayref() ) { $cmts{$row->[0]} = $row->[1]; } my @cmts = sort keys %cmts; eval { foreach $system (@cmts) { my $cisco = Net::Telnet::Cisco->new(Host => $cmts{$system +}); $cisco->login("$routeruser", "$routerpass"); $cisco->cmd( 'terminal length 0' ); $cisco->cmd( 'config t' ); foreach my $command (@config) { @config = $cisco->cmd($command); } $cisco->close; $results_text->insert('end', "$system - done\n"); } }; if ($@) { $results_text->insert('end', "\n$system Errored: $@\n\n"); } } ######### # Cores # ######### ######### sub cores { my (%core, $system); my $core = shift; $core->execute(); while (my $row = $core->fetchrow_arrayref() ) { $core{$row->[0]} = $row->[1]; } my @core = sort keys %core; eval { foreach $system (@core) { my $cisco = Net::Telnet::Cisco->new(Host => $core{$system +}); $cisco->login("$routeruser", "$routerpass"); $cisco->cmd( 'terminal length 0' ); $cisco->cmd( 'config t' ); $results_text->insert('end', "$system - done\n"); foreach my $command (@config) { @config = $cisco->cmd($command); } $cisco->close; } }; if ($@) { $results_text->insert('end', "\n$system Errored: $@\n\n"); } } ############ # Switches # ############ ############ sub switches { my (%switch, $system); my $switch = shift; $switch->execute(); while (my $row = $switch->fetchrow_arrayref() ) { $switch{$row->[0]} = $row->[1]; } my @switch = sort keys %switch; eval { foreach $system (@switch) { my $cisco = Net::Telnet::Cisco->new(Host => $switch{$syst +em}); $cisco->login("$routeruser", "$routerpass"); $cisco->cmd( 'terminal length 0' ); $cisco->cmd( 'config t' ); $results_text->insert('end', "$system - done\n"); foreach my $command (@config) { @config = $cisco->cmd($command); } $cisco->close; } }; if ($@) { $results_text->insert('end', "\n$system Errored: $@\n\n"); } } ######### # All # ######### ######### sub all { my (%cmts, %cores, %switches, $system); my $cmts = shift; my $core = shift; my $switch = shift; $cmts->execute(); $core->execute(); $switch->execute(); while (my $row = $cmts->fetchrow_arrayref() ) { $cmts{$row->[0]} = $row->[1]; } while (my $row = $core->fetchrow_arrayref() ) { $cores{$row->[0]} = $row->[1]; } while (my $row = $switch->fetchrow_arrayref() ) { $switches{$row->[0]} = $row->[1]; } my @cmts = sort keys %cmts; my @core = sort keys %cores; my @switch = sort keys %switches; eval { foreach $system (@cmts) { my $cisco = Net::Telnet::Cisco->new(Host => $cmts{$system +}); $cisco->login("$routeruser", "$routerpass"); $cisco->cmd( 'terminal length 0' ); $cisco->cmd( 'config t' ); $results_text->insert('end', "$system - done\n"); foreach my $command (@config) { @config = $cisco->cmd($command); } $cisco->close; } $results_text->insert('end', "\nRunning the submitted configur +ation for: All Cores\n\n"); foreach $system (@core) { my $cisco = Net::Telnet::Cisco->new(Host => $cores{$syste +m}); $cisco->login("$routeruser", "$routerpass"); $cisco->cmd( 'terminal length 0' ); $cisco->cmd( 'config t' ); $results_text->insert('end', "$system - done\n"); foreach my $command (@config) { @config = $cisco->cmd($command); } $cisco->close; } $results_text->insert('end', "\nRunning the submitted configuratio +n for: All Switches\n\n"); foreach $system (@switch) { my $cisco = Net::Telnet::Cisco->new(Host => $switches{$sy +stem}); $cisco->login("$routeruser", "$routerpass"); $cisco->cmd( 'terminal length 0' ); $cisco->cmd( 'config t' ); $results_text->insert('end', "$system - done\n"); foreach my $command (@config) { @config = $cisco->cmd($command); } $cisco->close; } }; if ($@) { $results_text->insert('end', "\n$system Errored: $@\n\n"); } } ######### # About # ######### ######### sub about { my $mesg = $w->MesgBox( -title => 'About', -text => "Author: Jason Riedel\nVersion: 1.0\nReleased 5/16 +/2003\nPurpose: To change cisco configuration for our cisco devices i +n a simple easy GUI.\n", -buttons => ['OK'] ); $mesg->Show; } ######### # End # ######### ######### sub end { exit; }

In reply to Tk Widget Updating from a foreach loop by ypcat

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.