How do you give functions private variables that retain their values between calls?



How do you give functions private variables that retain their values between calls?..

Answer / Preety Rani

In Perl, there's no strict concept of private variables within a function. However, you can use lexical (my) variables to create scope for variables and ensure they persist within the function's context.nn``perlnsub my_function { # Function definition n my $my_var = 'Some value'; # Declare a lexical variable inside the functionn}n"`

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More CGI Perl Interview Questions

What is the difference between perl array and perl hash?

1 Answers  


How would you replace a char in string and how do you store the number of replacements?

2 Answers  


Does Perl have reference type?

1 Answers  


What are the benefits of perl in using it as a web-based application?

1 Answers  


Explain goto label, goto name, and goto expr?

1 Answers  


Enlist the advantages of using c over perl?

1 Answers  


What can be done for efficient parameter passing in perl?

1 Answers  


Mention what is cpan?

1 Answers  


Why we use CGI?

1 Answers   Wipro,


what is Polymorphism in Perl?

1 Answers  


How will you open a file in read-only mode in perl?

1 Answers  


Explain lists and ivalue?

1 Answers  


Categories