in reply to Binding Tk events

The problem is in how you are passing the arguments to &mysub.
The following is from "Mastering Perl/Tk":

"When you want to pass arguments to a callbakc, specify an array reference, with the callback code reference as the first element and the callback arguments as the subsequent array elements"

In other words: instead of
$input->bind('<Return>', [\&mysub($arg)]);
you need to have
$input->bind('<Return>', [\&mysub, $arg]);

hope this helps,
davidj

UPDATE
My solution is NOT correct for calling subs with bind.
It is only correct for calling subs with arguments when using the -command widget option.
Please refer to dave_the_m's post below for the correct solutin.
Sorry for the post.

davidj

Replies are listed 'Best First'.
Re: Re: Binding Tk events
by graff (Chancellor) on Jun 02, 2004 at 01:46 UTC
    $input->bind('<Return>', [\&mysub, $arg]);
    ... UPDATE
    My solution is NOT correct for calling subs with bind...

    On the contrary, your solution, forming an anonymous array containing a subroutine ref followed by args to be passed to the sub, is entirely correct. It's the idiom that I normally use for bind calls of this sort.

Re: Re: Binding Tk events
by Scarborough (Hermit) on Jun 01, 2004 at 15:47 UTC
    Thanks I think this is my problem in a nut shell. Mastering perl/Tk is this an actual book or a web resource?
      Mastering Perl/Tk is an O'Reilly book. You can find it on O'Reilly's web site.

      davidj