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

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.