in reply to Scope with Perl/Tk

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

Replies are listed 'Best First'.
Re: Re: Scope with Perl/Tk
by Anonymous Monk on Oct 12, 2001 at 07:23 UTC
    That worked like a charm. Thanks a bunch!