PERL interview questions

PERL quiz questions

  • 1.

    Explain what is the function of Return Value?


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

  • 2.

    Explain what are prefix dereferencer and list them out?


    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
  • 3.

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


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

  • 4.

    Explain what is lvalue?


    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.

  • 5.

    Explain what is Perl one liner?


    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

  • 6.

    What is the closure in PERL?


    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.

  • 7.

    Explain what is STDIN, STDOUT and STDERR?


    • 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.
  • 8.

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


    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.
  • 9.

    Explain what is Polymorphism in Perl?


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

  • 10.

    Mention what is CPAN?


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

  • 11.

    Explain what is Chop & Chomp function does?


    • 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.
  • 12.

    Explain USE and REQUIREMENT statements?


    • 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

  • 13.

    Mention how many ways you can express string in Perl?


    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)
  • 14.

    What does -> symbol indicates in Perl?


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

  • 15.

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


    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.

  • 16.

    What is the syntax used in Perl grep function?


    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
  • 17.

    In Perl, what is grep function used for?


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

  • 18.

    Mention the difference between die and exit in Perl?


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

  • 19.

    Explain which feature of PERL provides code reusability?


    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.

  • 20.

    List the operator used in Perl?


    Operators used in Perl are

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

© 2017