Core Function MKFunc
From Sputnik Wiki
MKFunc ( <params>, <body> )
Contents |
Description
Create a user defined function to be called from a variable.
params
A string that will be the functions parameters.
body
A string that will be the functions body.
Return Value
Success: A function variable that can be called later when needed.
Failure: Returns null
Remarks
The body does not need a { } block it already includes one in the build.
Example
Simple hello world with no params
my $Func = MKFunc('', 'println("Hello World");'); CallFunc($Func);
One with params
my $Func = MKFunc('$a, $b', 'println("Value is: " . ($a + $b));'); CallFunc($Func, array(10, 20));
Same as above but this time using the function(){} statement instead of MKFunc
my $Func = Function(){ println("Hello World");}; CallFunc($Func); my $Func = Function( $a, $b ){ println("Value is: " . ($a + $b)); }; CallFunc($Func, array(10, 20));
Same as above but this time calling directly instead of using CallFunc
my $Func = Function( $a, $b ){ println("Value is: " . ($a + $b)); }; $Func(10, 20);