in reply to Re: Re: Passing arguments to callback routines with named references
in thread Passing arguments to callback routines with named references
# generate a closure: sub gen_change_mode { my $mode = shift; return { # same code as in change_mode }; } # then do this $main->Button(-text => 'To Upper Case', -command => gen_change_mode(2) )->pack; # or this $some_ref = gen_change_mode(3); $main->Button(-text => 'To Mixed Case', -command => $some_ref )->pack;
so in the last case gen_change_mode(3) will return a code reference with $mode set as 3, meaning you can pass this around as a code ref, which is what you're after.
there is an example in `perldoc perlref` which uses a lexical (my) var inside the anon sub that gets returned, so you can pass more arguments to it when you finally run it as a subroutine.
|
|---|