Passing Parameters by Reference
Learn the ways by which we can pass values to a subroutine by reference.
We'll cover the following
What is pass by reference?
When passing arguments by reference, the original value is passed. Therefore, the original value gets altered. In pass by reference, we actually pass the value and access them using $_[index]
where the index is the variable sequence passed. It tells the compiler that the data is a reference to the value rather than simply the value itself.
Example: swap numbers
Now let’s redefine the swap
subroutine from the example in the previous lesson.
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy