in reply to Re: Re: Passing arguments to callback routines with named references
in thread Passing arguments to callback routines with named references

Actually, bobn is not right in this case. Your "case 2" is very close to the mark -- the right way would be:
my $change_mode = \&change_mode; ... # Case 2: Callback routine called with argument (corrected): # given that $change_mode is a ref to a sub $main->Button(-text => 'To Upper Case', -command => [ $change_mode, 2 ] )->pack;
The "-command" option on Tk widgets (like the "bind" method) can accept an array ref (anonymous in this case), in which the first element of the array is the subroutine reference, and the remaining elements are args to pass to the sub.

The "bind" case is a little different, because the sub will actually get the widget handle that invoked it as the first arg every time a "bound" event triggers the sub, whereas the "-command" option does not pass the widget handle as the first arg.

  • Comment on Re: Re: Re: Passing arguments to callback routines with named references
  • Download Code

Replies are listed 'Best First'.
Re: Re: Re: Re: Passing arguments to callback routines with named references
by bobn (Chaplain) on Jul 15, 2003 at 05:19 UTC

    Well, that's a style I don't see everyday, but perldoc Tk::callbacks says exactly that - use the array reference and this can be done as shown.

    --Bob Niederman, http://bob-n.com