Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm doing something like this;
$widget->my_mega_widget(-command => \&do_something);
Problem is I want to have &do_something be a method ala;
$widget->my_mega_widget(-command => $self->do_something);
Can anyone help me with the syntax, or tell me the proper way?

Replies are listed 'Best First'.
Re: callbacks in Tk
by Tanktalus (Canon) on Sep 24, 2005 at 02:46 UTC
    $widget->my_mega_widget(-command => sub { $self->do_something });

    You want a closure. We've had a number of discussions recently on closures, so I'm not going to repeat them, but urge you to search with that term.