How can you define “my” variables scope in Perl and how it is different from “local” variable scope?
Answer / Durga Rani
In Perl, a my variable is a lexical (or local) variable with a scope limited to the current block. It is created when first used within that block and destroyed when the block ends. On the other hand, a local variable has a broader scope: it is visible in the entire enclosing subroutine. The main difference between my and local variables is their lifetime and visibility: my variables are created and destroyed based on blocks, while local variables exist for the duration of the subroutine.
| Is This Answer Correct ? | 0 Yes | 0 No |
what is CPAN?
What are the two ways to get private values inside a subroutine?
What are prefix dereferencer?
Explain the difference between "my" and "local" variable scope declarations. ?
Why aren't Perl's patterns regular expressions?
what is the function of Return Value?
What $! In perl?
What happens to objects lost in "unreachable" memory, such as the object returned by Ob->new() in `{ my $ap; $ap = [ Ob->new(), $ap ]; }' ?
What happens in dereferencing?
Explain the meaning of closure in perl.
What are some common methods to all handles in perl?
How to change a directory in perl?