PERL interview questions

PERL quiz questions

  • 1.

    Explain what is the function of Return Value?

    Answer:

    The Return Value function returns a reference to an object blessed into CLASSNAME.

    View
  • 2.

    Explain what are prefix dereferencer and list them out?

    Answer:

    Using a particular prefix when you dereference a variable, they are called prefix dereferencer.

    • $- Scalar variables
    • %-Hash variables
    • @-Arrays
    • &-Subroutines
    • Type globs-*myvar stands for @myvar, %myvar
    View
  • 3.

    Explain what is the function that is used to identify how many characters are there in a string?

    Answer:

    To tell how many characters are there in a string, length () function is used.

    View
  • 4.

    Explain what is lvalue?

    Answer:

    An lvalue is a scalar value which can be used to store the result of any expression. Usually, it appears at the left-hand side of the expression and represent a data space in memory.

    View
  • 5.

    Explain what is Perl one liner?

    Answer:

    One liner is one command line programs and can be executed from the command line immediately.

    For example,

    # run program under the debugger

    perl-d my_file

    View
  • 6.

    What is the closure in PERL?

    Answer:

    The closure is a block of code that is used to capture the environment where it is defined. It particularly captures any lexical variables that block consists of and uses in an outer space.

    View
  • 7.

    Explain what is STDIN, STDOUT and STDERR?

    Answer:

    • STDIN: The STDIN file handle is used to read from the keyboard
    • STDOUT: It is used to write into the screen or another program
    • STDERR: It is also used to write into a screen. STDERR is a standard error stream that is used in Perl.
    View
  • 8.

    Mention what are the two ways to get private values inside a subroutine or block?

    Answer:

    There are two ways through which private values can be obtained inside a subroutine or block

    • Local Operator: On global variables only this operator can operate. The value of the private variable is saved on the Local Operator and makes the provision to restore them at the end of the block
    • My Operator: To define or create a new variable this operator can be used. Variable that is created by My Operator will always be declared private to block inside which it is defined.
    View
  • 9.

    Explain what is Polymorphism in Perl?

    Answer:

    In Perl, Polymorphism means the methods defined in the base class will always over-ride the methods defined in the parent class.

    View
  • 10.

    Mention what is CPAN?

    Answer:

    CPAN means Comprehensive Perl Archive Network, a large collection of Perl software and documentation.

    View
  • 11.

    Explain what is Chop & Chomp function does?

    Answer:

    • Chop function eliminates the last character from expr, each element of the list
    • Chomp function eliminates the last character from an expr or each element of the list if it matches the value of $/. It is considered better than chop as it only removes the character if there is a match.
    View
  • 12.

    Explain USE and REQUIREMENT statements?

    Answer:

    • REQUIRE statement: It is used to import functions with a global scope such that their objects and functions can be accessed directly

    Example: Require Module,

    Var=module::method(); //method called with the module reference

    • USE statements are interpreted and are executed during parsing, while during run time the require statements are executed.

    Example: Use Module

    Var=method(); //method can be called directly

    View
  • 13.

    Mention how many ways you can express string in Perl?

    Answer:

    You can express string in Perl in many ways

    For instance “this is quizbucket.”

    • qq/this is quizbucket like double quoted string/
    • qq^this is quizbucket like double quoted string^
    • q/this is quizbucket/
    • q&this is quizbucket&
    • q(this is quizbucket)
    View
  • 14.

    What does -> symbol indicates in Perl?

    Answer:

    In Perl, the arrow – > symbol is used to create or access a particular object of a class.

    View
  • 15.

    Explain what is the scalar data and scalar variables in Perl?

    Answer:

    Scalar in Perl means a single entity like a number or string. So, the Java concept of int, float, double and string equals to perls scalar and the numbers and strings are exchangeable. While scalar variable is used to store scalar data. It uses $ sign and followed by one or more alphanumeric characters or underscore. It is a case sensitive.

    View
  • 16.

    What is the syntax used in Perl grep function?

    Answer:

    The syntax used in Perl is

    a) grep BlOCK LIST

    b) grep ( EXPR, LIST )

    • BLOCK: It contains one or more statements delimited by braces, the last statement determines in the block whether the block will be evaluated true or false.
    • EXPR: It represents any expression that supports $, particularly a regular expression. Against each element of the list, expression is applied, and if the result of the evaluation is true, the current element will be attached to the returned list
    • LIST: It is a list of elements or an array
    View
  • 17.

    In Perl, what is grep function used for?

    Answer:

    To filter the list and return only those elements that match certain criteria Perl grep function is used.

    View
  • 18.

    Mention the difference between die and exit in Perl?

    Answer:

    Die will print a message to the std err before ending the program while Exit will simply end up the program.

    View
  • 19.

    Explain which feature of PERL provides code reusability?

    Answer:

    To provide code re-usability in PERL inheritance feature is used. In Inheritance, the child class can use the methods and property of the parent class.

    View
  • 20.

    List the operator used in Perl?

    Answer:

    Operators used in Perl are

    • String Concatenation à ‘.’
    • Comparison Operators à ==, !=, >,< , >=
    • Logical Operators à &&, ll , !
    • Assignment Operators à + = ,- + , *=
    • Increment and decrement Operators à ++ ,-
    • Arithmetic Operators à +, – ,*
    View

© 2017 QuizBucket.org