Passing Parameters by Value
Learn how to pass the value of actual parameters to a subroutine.
We'll cover the following
Perl allows us to pass arguments into a subroutine in two ways:
- Pass by Value
- Pass by Reference
Let’s take a look at the pass by value method.
Arguments passed by value
On passing arguments by value, the value of the argument may change within a subroutine, but the original value outside the subroutine remains unchanged. That means a duplicate of the original value is passed as an argument.
Example: a cube of a number
Consider the following program that accepts a number and prints its cube:
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy