Solution Review: Sum of Two Numbers
Understand how to handle parameters in Perl subroutines by exploring a solution that sums two numbers. This lesson explains accessing function arguments using @_ and returning their sum effectively.
We'll cover the following...
We'll cover the following...
Let’s look at the solution first, before jumping into the explanation:
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.