Interview Questions Answers.ORG
Interviewer And Interviewee Guide
Interviews
Quizzes
Home
Quizzes
Interviews Coding/Programming Interviews:Active Template Library (ATL)ActiveXApplication DeveloperArtificial intelligenceAssemblyAssociate Software EngineerAWKAWTC ProgrammingC++ ProgrammingCGI PerlCGI ProgrammingCMMICobolCritical ReasoningData Structures TreesDCOM COMDelphiDTDE4XExtensible Stylesheet Language (XSL)FortranFull-Stack DeveloperHaskellHTML DOMILUIPhone DeveloperJasper Reports DeveloperJava DeveloperLisp ProgrammingLotus NotesMicrosoft Foundation Class (MFC)Mobile DeveloperMVC DeveloperNode.jsOOPPascalPerl ProgrammingPHPPHP DeveloperProgrammingProgramming AlgorithmsProgramming ConceptsPythonRubyRuby on RailsRuby on Rails DeveloperSenior Front End DeveloperSenior Software DeveloperSignature ProgramSOASocket ProgrammingSoftware Development EngineerSoftware engineeringSr. PHP ProgrammerStack And QueueSTLSwift DeveloperTCL (Tool Command Language)Team Leader Android DeveloperUMLUnity 2D Games DeveloperUnity 3D DeveloperUnity DeveloperVBA (Visual Basic for Applications)Visual Basic (VB)Visual C++Web DevelopmentWin32APIWindows ProgramingWordPress DevelopmentWSDLXFormsXHTMLXLinkXMLXPathXQueryXSL-FOXSLT
Copyright © 2018. All Rights Reserved
Perl Programming Interview Question:
How do you give functions private variables that retain their values between calls?
Submitted by: AdministratorCreate a scope surrounding that sub that contains lexicals.
Only lexical variables are truly private, and they will persist even when their block exits if something still cares about them. Thus:
{ my $i = 0; sub next_i { $i++ } sub last_i { --$i } }
creates two functions that share a private variable. The $i variable will not be deallocated when its block goes away because next_i and last_i need to be able to access it.
Submitted by: Administrator
Only lexical variables are truly private, and they will persist even when their block exits if something still cares about them. Thus:
{ my $i = 0; sub next_i { $i++ } sub last_i { --$i } }
creates two functions that share a private variable. The $i variable will not be deallocated when its block goes away because next_i and last_i need to be able to access it.
Submitted by: Administrator
Copyright 2007-2025 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.
https://InterviewQuestionsAnswers.ORG.