PERL interview questions

PERL quiz questions

  • 1.

    Can we load binary extension dynamically?

    Answer:

    Yes, we can load binary extension dynamically but your system supports that. If it doesn’t support, then you can statically compile the extension.

    View
  • 2.

    Does Perl have objects? If yes, then does it force you to use objects? If no, then why?

    Answer:

    Yes, Perl has objects and it doesn’t force you to use objects. Many object oriented modules can be used without understanding objects. But if the program is too large then it is efficient for the programmer to make it object oriented.

    View
  • 3.

    Write the program to process a list of numbers.

    Answer:

    The following program would ask the user to enter numbers when executed and the average of the numbers is shown as the output:

    $sum = 0;
     
    $count = 0;
     
    print "Enter number: ";
     
    $num = <>;
     
    chomp($num);
     
    while ($num >= 0)
     
    {
     
    $count++;
     
    $sum += $num;
     
    print "Enter another number: ";
     
    $num = <>;
     
    chomp($num);
     
    }
     
    print "$count numbers were entered\n";
     
    if ($count > 0)
     
    {
     
    print "The average is ",$sum/$count,"\n";
     
    }
     
    exit(0);

     

    View
  • 4.

    In Perl we can show the warnings using some options in order to reduce or avoid the errors. What are that options?

    Answer:

    -The -w Command-line option: It will display the list if warning messages regarding the code.

    – strict pragma: It forces the user to declare all variables before they can be used using the my() function.

    – Using the built-in debugger: It allows the user to scroll through the entire program line by line.

    View
  • 5.

    Which feature of Perl provides code reusability ? Give any example of that feature.

    Answer:

    Inheritance feature of Perl provides code reusability. In inheritance, the child class can use the methods and property of parent class

    Package Parent;
     
    Sub foo
     
    {
     
    print("Inside A::foo\n");
     
    }
     
    package Child;
     
    @ISA = (Parent);
     
    package main;
     
    Child->foo();
     
    Child->bar();

     

    View
  • 6.

    Create a function that is only available inside the scope where it is defined ?

    Answer:

    $pvt = Calculation(5,5);
     
    print("Result = $pvt\n");
     
    sub Calculation{
     
    my ($fstVar, $secndVar) = @_;
     
    my $square = sub{
     
    return($_[0] ** 2);
     
    };
     
    return(&$square($fstVar) + &$square($secndVar));
     
    };

    Output: Result = 50

    View
  • 7.

    Difference between the variables in which chomp function work ?

    Answer:

    Scalar: It is denoted by $ symbol. Variable can be a number or a string.

    Array: Denoted by @ symbol prefix. Arrays are indexed by numbers.

    The namespace for these types of variables is different. For Example: @add, $add. The scalar variables are in one table of names or namespace and it can hold single specific information at a time and array variables are in another table of names or namespace. Scalar variables can be either a number or a string

    View

© 2017 QuizBucket.org