Re: Passing values to CodeRefs



On Wed, 2007-01-10 at 12:00 -0600, Nik Ogura wrote:
Whats the syntax for calling a coderef with arguments here?

In addition to Emmanuele's answer which relies on the implementation of
the GTK-Perl wrapper, the generic Perl answer is to use an anonymous
subroutine:

this works:   $widget->signal_connect(clicked => \&rankChanged);

this doesnt:  $widget->signal_connect(clicked => \&rankChanged($arg));

  $widget->signal_connect(clicked => sub { rankChanged($arg) });

If you also want your 'rankChanged' function to get the arguments
normally passed to a 'clicked' event handler, you could pass them like
this:

  $widget->signal_connect(clicked => sub { rankChanged($arg, @_) });

Strictly speaking, you're not passing values to a code ref, but defining
a code ref that has knowledge of the values.

Regards
Grant




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]