use Net::Telnet; use Tk; use XML::Simple; use strict; use warnings; use constant HOST => "1"; use constant USERNAME => "2"; use constant PASSWORD => "3"; my $tasks = XMLin("command.xml"); my $mw = MainWindow->new(); my $list; $list = $mw->Scrolled("Listbox", yscrollcommand => sub {show_detail($list->curselection())}, -scrollbars=>"e")->pack(-fill => 'x'); $list->bind("<1>", sub {show_detail($list->curselection())}); $list->bind("", sub {doit($list->curselection())}); my $detail = $mw->Scrolled("Text", -width => 40, -height=>10, -scrollbars=>"e")->pack(-fill => 'x'); for my $id (0..$#{@{$tasks->{"task"}}}) { $list->insert("end", $tasks->{"task"}->[$id]->{"description"}); } MainLoop; sub doit { my $task_id = shift; my $t = new Net::Telnet(timeout => 10, Prompt => '/\[AAUA1\]/'); $t->open(HOST); $t->login(USERNAME, PASSWORD); my $cmds = $tasks->{"task"}->[$task_id]->{"command"}; for (0..$#{@{$cmds}}) { my @lines = $t->cmd($cmds->[$_]->{"string"}); print @lines; } } sub show_detail { my $task_id = shift; $detail->delete("\@1,1", "end"); my $cmds = $tasks->{"task"}->[$task_id]->{"command"}; for (0..$#{@{$cmds}}) { $detail->insert("end", $cmds->[$_]->{"string"} . "\n"); } }