pg has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to throw something together quickly, but ran into this problem. Code is like this at this moment:
use Net::Telnet; use Tk; use Data::Dumper; use XML::Simple; use strict; use warnings; my $tasks = XMLin("command.xml"); print Dumper($tasks); my $mw = MainWindow->new(); for (0..$#{@{$tasks->{"task"}}}) { $mw->Button(text => $tasks->{"task"}->[$_]->{"description"}, c +ommand => sub {pub($_)})->pack(); } MainLoop; sub pub { my $task_id = shift; print "task id = $task_id\n"; my $t = new Net::Telnet(timeout => 10, Prompt => '[AATS1]$'); $t->open("ofgaix2"); $t->login("rpts1", "aats1"); my @lines; my $cmds = $tasks->{"task"}->[$task_id]->{"command"}; for (0..$#{@{$cmds}}) { @lines = $t->cmd($cmds->[$_]->{"string"}); print @lines; } }
The problem is that $task_id is not properly passed into the sub. All what I need is a way to identify who triggered the sub.
Thanks in advance.
By the way, there might be multiple ways to resolve it, at the same time, I am still interested in whether Tk itself provides a way to find out who trigger the action.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Quick question about Tk(?)
by Arunbear (Prior) on Sep 24, 2004 at 16:15 UTC | |
by pg (Canon) on Sep 24, 2004 at 16:17 UTC | |
|
Re: Quick question about Tk(?)
by BrowserUk (Patriarch) on Sep 24, 2004 at 16:33 UTC | |
|
Re: Quick question about Tk(?)
by JediWizard (Deacon) on Sep 24, 2004 at 16:08 UTC | |
by pg (Canon) on Sep 24, 2004 at 16:14 UTC | |
by Arunbear (Prior) on Sep 24, 2004 at 16:26 UTC | |
|
Re: Quick question about Tk(?)
by qumsieh (Scribe) on Sep 24, 2004 at 17:07 UTC |