Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reference to a function and a parameter in the same time 2

Status
Not open for further replies.

CristianLuca

Programmer
Oct 25, 2007
36
0
0
RO
hey guys , how can i pass a parameter to a function reference when i assign it. like

my $funcAddr = \&foo($param)


thanks
 
I don't think you can.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Code:
( my $ref = \&foo )->( $param );
Not sure why you'd want to though.
 
used in tk::widget { -command => \&foo }

but i have several widgets that use the same function but with different paramenters :

tk::widgeOne { -command => \&foo($paramWOne )}
tk::widgeTwo { -command => \&foo($paramWTwo )}
tk::widgeThree { -command => \&foo($paramWThree)}
 
too bad you can't edit :
typo : tk::widgeOne { -command => [\&foo, ($paramWOne] }

correct : tk::widgeOne { -command => [\&foo, $paramWOne] }
 
Be careful, luca, that form of callback will call your function with the value of the variable at the time of calling: this means that the variable must be global, as function [tt]foo[/tt] must know it, and have a meaningful value.
If by contrast you need to substitute with the value the variable has when you call [tt]tk::widgeOne[/tt], you need to do [tt]tk::widgeOne{-command=>[\&foo,Tk::Ev($paramWOne)]}[/tt]. Note however that I use this with [tt]Tkx::[/tt], not sure if it works the same with [tt]Tk::[/tt]


Franco
: Online engineering calculations
: Magnetic brakes for fun rides
: Air bearing pads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top