Passing Variable from user defined function is done by using the values declared outside a function, make the
neccessary calculation inside the function and then return the result whenever the function is called.If you are passing
variables to a function there is an array @_ which lists all the variables when the function is called, to improve the
usability of a function.
Example:
#! C:\programfiles\perl\bin\perl
print "content-type: text/html\n\n";
$x = 12;
$y = 13;
$sum = add($x, $y);
print "The SUM is:",$sum;
sub add
{
my ($a, $b) = @_;
$c = $a + $b;
return $c;
}
Result:
The SUM is:25
In the above passing variable example the values of variables "$x=12","$y=13" is passed to the values "$a","$b"
to do addition inside the function to store the values in "$c", the output is go outside the loop in the variable "$sum".
A Note
Simple introduction, basic CGI perl programming codes with examples.
Do send your feedback or suggestions on this tutorial.
This is a copyright content.