in reply to Passing arguments to callback routines with named references
You've already gotten lots of good explanations and answers. In your case, graff's node sounds like the best answer.
I just want to offer another suggestion for the general case.
What is the proper syntax for passing arguments to a subroutine that has a named reference when using callbacks?
You can use closures, as dank suggested; but you can do it without copying the whole subroutine body and you can make it general.
sub callback { my $coderef = shift; my @args = @_; sub { $coderef->(@args) } }
That will allow you to write things like
but will work with any coderef (named or not) and arguments.-command => callback($change_mode, 3),
-sauoq "My two cents aren't worth a dime.";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Passing arguments to callback routines with named references
by liz (Monsignor) on Jul 15, 2003 at 13:58 UTC | |
by sauoq (Abbot) on Jul 15, 2003 at 17:28 UTC | |
by liz (Monsignor) on Jul 15, 2003 at 22:21 UTC | |
by ctilmes (Vicar) on Jul 15, 2003 at 14:09 UTC | |
by liz (Monsignor) on Jul 15, 2003 at 15:21 UTC |