How can you define “my” variables scope in Perl and how it is different from “local” variable scope?



How can you define “my” variables scope in Perl and how it is different from “loca..

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

Post New Answer

More CGI Perl Interview Questions

what is CPAN?

1 Answers  


What are the two ways to get private values inside a subroutine?

1 Answers  


What are prefix dereferencer?

1 Answers  


Explain the difference between "my" and "local" variable scope declarations. ?

1 Answers   HCL,


Why aren't Perl's patterns regular expressions?

1 Answers  


what is the function of Return Value?

1 Answers  


What $! In perl?

1 Answers  


What happens to objects lost in "unreachable" memory, such as the object returned by Ob->new() in `{ my $ap; $ap = [ Ob->new(), $ap ]; }' ?

1 Answers  


What happens in dereferencing?

1 Answers  


Explain the meaning of closure in perl.

1 Answers  


What are some common methods to all handles in perl?

1 Answers  


How to change a directory in perl?

1 Answers  


Categories