Hello,
Does any body know if PERl supports function templates just as C++ does. I have heard of object-oriented PERL. Hence, wanted to use the feature. Please give the snippet of code also in case u have any.
Thanks,
sreemakam
in C++ you would have:
- int something( int arg1, int arg2 )
-
{
-
...processing...
-
}
in PERL this is done as follows:
- sub something
-
{
-
...processing...
-
}
and called by putting an ampersand (&) at the front of the function name:
-
&something( val1, val2 );
Input parameters are passed via the @_ array variable.
SO a sample function would be:
- sub ADD
-
{
-
$val1 = $_[0];
-
$val2 = $_[1];
-
-
return $val1 + $val2;
-
}
-
-
-
$answer = &ADD( 2, 3 );