$sum = add(3, 5);
print $sum."\n";
sub add
{
$a = shift;
$b = shift;
return ($a + $b);
}
Yes, it prints 8.
Now what about the following code?
$sum = add(3, 5);
print $sum."\n";
sub add
{
$a = shift;
$b = shift;
}
hmm... what should it print? It prints 5 ! A garbage value?
Not actually. I have found that in Perl if you don't return anything, it returns the value of the last variable in the function.
Now you can tell the output of the following code :-)
$sum = add(3, 5);
print $sum."\n";
sub add
{
$a = shift;
$b = shift;
$c = 10;
}
yes, it's 10 !
