Solution Review: Sum of Two Numbers

In this lesson, we'll look at the explanation of the previous challenge.

We'll cover the following

Let’s look at the solution first, before jumping into the explanation:

Press + to interact
sub sum{
return @_[0] + @_[1];
}
print sum(10, 5);

Explanation

To access the parameters of the function, we can use @_. To access the first parameter, we use @_[0], and to get the second parameter, we use @_[1]. Then, we simply return their sum.