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.
In reply to Quick question about Tk(?) by pg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |