Explain the difference between declarations of 'my' and 'local' variable scope in perl?



Explain the difference between declarations of 'my' and 'local' variable scope i..

Answer / Rukmani

In Perl, the 'my' keyword creates a lexical (or private) variable that is only accessible within the current scope. The variable will be destroyed when the subroutine or block ends. On the other hand, 'local' declares a dynamic (or package) variable that can be accessed by any function in the same package. However, unlike 'my', 'local' variables retain their values between function calls.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More CGI Perl Interview Questions

How to open a directory in perl?

1 Answers  


How do you open a file for writing?

6 Answers  


What is warn function in perl?

1 Answers  


What does -> symbol indicates in Perl?

1 Answers  


“The methods defined in the parent class will always override the methods defined in the base class”. What does this statement means?

1 Answers  


How can you replace the characters from a string and save the number of replacements?

1 Answers  


What does file test operators do in perl?

1 Answers  


Write a program to show the process of spawning a child process

1 Answers  


What is the easiest way to download the contents of a URL with Perl?

1 Answers  


Does Perl have reference type?

1 Answers  


What is the difference between chop & chomp functions in perl?

10 Answers   Cap Gemini, DELL, Electronic Data, TCS,


You want to empty an array. How would you do that?

1 Answers  


Categories