G'day berniep,

When you create your button with:

-command => [\&Account_Setup, $acct]
It uses the value of $acct that exists at the time the button is created. If that value of $acct is then changed later on, the button isn't going to pick up on this.

Instead of passing in $acct (which gives you the contents of the $acct variable), you can instead pass in a reference to the variable:

-command => [\&Account_Setup, \$acct]
Now, when your button is pressed, it gets a reference to $acct, which you can dereference to get the current value of $acct, like this:
sub Account_Setup { my $acct_type = ${shift()}; print "Account Type: $acct_type\n"; }
This should hopefully solve your problem.

Trap for the unwary:It's important to use ${shift()} rather than ${shift}. The first is calling perl's built-in shift function and then de-referencing the result into a scalar. The second is the varaible named $shift.

Cheers,
Paul


In reply to Re: Scope with Perl/Tk by pjf
in thread Scope with Perl/Tk by berniep

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.