Hi all... I have been programming a world clock using Perl/Tk. I am fairly new to Perl (and more so to Tk). I am stuck at one point when I have to click a button and this leads to a subroutine. The first thing in that subroutine is that every existing slave, including the calling button, should be unpacked. I originally made all these widgets available to the whole script, so that I did not need to pass them to the subroutine, but now I am trying to prune my code so that so that variable scope is as limited as possible, and that's why I need to pass these widgets (variables) to a separate subroutine. My code is something like this...
{##### block of code ##### my $button2 = $frame2->Button(-text => "Label", -command => \&subroutine2($label2, $frame2, $button1, $button2))->pack +(); ##### block of code ends here ##### } sub subroutine2{ foreach @_{ packForget $_; } ##### rest of subroutine ##### }
I don't know if this is even a legal call. But this does not seem to work even if I do not pass $button2. Can you please suggest a way out of this? Thanks a lot for your help.

the wyrds - learn, learn, learn.

In reply to passing a button in its own -command option by sannu

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.