300+ TOP PERL MCQ Questions and Answers Quiz

PERL Multiple Choice Questions

1. What are the benefits of the Perl programming language?

  1. Easy to learn
  2. Text Processing
  3. Easy to be embedded on web pages
  4. All of these

Answer: D All of these

Explanation: Some benefits of Perl are:

  • Easy to learn
  • Easy of text processing
  • Easy to embed on web pages

2. What is the file extension for the Perl program?

  1. .pl
  2. .perl
  3. .prl
  4. None of these

Answer: A .pl

Explanation: The extension .pl is used to create a Perl file.

3. What is the syntax to create multiline comments in Perl?

  1. =start
    =end
  2. #begin
    #cut
  3. =begin
    =cut
  4. None of these

Answer: C =begin
=cut

Explanation: The syntax for creating a multiline comment in Perl is:

=begin
=cut

4. Perl Programming language is ___?

  1. General purpose programming language
  2. Dynamic programming language
  3. High-level interpreted programming language
  4. All of these

Answer: D All of these

Explanation: Perl is a general-purpose, high-level interpreted, and dynamic programming language.

5. The creator of Perl programming language is ___.

  1. James Gosling
  2. Brendan Eich
  3. Larry Wall
  4. Bjarne Stroustrup

Answer: C Larry Wall

Explanation: American Programmer Linguist Larry Wall, in December 1987 created Perl. The version Perl 1.0 was released for computers running on the UNIX operating system.

6. The year in which Perl was launched?

  1. 1986
  2. 1987
  3. 1988
  4. 1878

Answer: B 1987

Explanation: In December 1987, American Programmer Linguist Larry Wall created Perl. The version Perl 1.0 was released for computers running on the UNIX operating system.

7. What are the disadvantages of Perl over C/C++?

  1. No main() [driver] function
  2. Support closures
  3. It is interpreted language
  4. None of these

Answer: D None of these

Explanation: The Perl programming language is better than the C/C++ programming language. So common advantages include:

  • No main () function that acts as entry point to the program.
  • It is interpreted language leading to faster compilation.

8. Which of the following is not a concept of OOP?

  1. Encapsulation
  2. Class
  3. Abstraction
  4. None of these

Answer: D None of these

Explanation: The concepts of OOPs are:

  • Class
  • Object
  • Method
  • Polymorphism
  • Inheritance
  • Encapsulation
  • Abstraction

9. Method in Perl is?

  1. Time savers
  2. User to reuse code w/o retyping the code
  3. Collections of statement that perform specific tasks
  4. All of these

Answer: D All of these

Explanation: Method/subroutine in Perl is a block of code (collection of statements) that performs a specific task in peril.

It can save programmer time and user code as one function can be called multiple times.

10. Is the following statement correct for Perl?
“Data Abstraction displays only the essential details to the user”

  1. TRUE
  2. FALSE

Answer: A TRUE

Explanation: Data Abstraction displays only the essential details to the user. It is the process of binding together data and related functions in a single unit.

PERL Objective Questions
PERL MCQs

11. What is the correct syntax for defining a class in Perl?

  1. package class_name
  2. class class_name
  3. new class class_name
  4. new package class_name

Answer: A package class_name

Explanation: The correct syntax for creating a class in Perl is:

    package class_name

12. Object in Perl an instance of a class?

  1. TRUE
  2. FALSE

Answer: A TRUE

Explanation: Objects are instances of class.

13. What is called when an object is created in Perl?

  1. Destructor
  2. Constructor
  3. Variable
  4. All of these

Answer: D All of these

Explanation: The constructor of a class is the first subroutine to be called when an object of that class is initiated.

14. What is the correct syntax for creating a new object in Perl?

  1. var object_name = new class_name()
  2. new object_name = class_name()
  3. my object_name = new class_name()
  4. None of these

Answer: C my object_name = new class_name()

Explanation: The correct syntax for creating an object in Perl is:

    my object_name = new class_name()

15. Which of these is not a type of method in Perl?

  1. Static method
  2. Constant method
  3. Virtual method
  4. All of these

Answer: B Constant method

Explanation: Virtual methods and static methods are valid types of methods in Perl.

16. What will be the output of the following Perl code?

use strict;
use warnings;
package vehicle;

sub set_mileage{
my $class = shift;

my $self = {
‘distance’=> shift,
‘petrol_consumed’=> shift
};

bless $self, $class;
return $self;
}

sub get_mileage{
my $self = shift;
my $result = $self->{‘distance’} / $self->{‘petrol_consumed’};

print “$result\n”;
}

my $ob1 = vehicle -> set_mileage(2550, 175);
$ob1->get_mileage();

  1. 15
  2. 15.00
  3. 14.5714285714286
  4. None of these

Answer: C 14.5714285714286

17. Destructor’s in Perl are ___.

  1. Used for cleanup of reference of objects
  2. Called at the start of the program
  3. Not a program
  4. All of these

Answer: A Used for cleanup of reference of objects

Explanation: Destructors in Perl are called when the object goes out of scope. It is used to clean up the reference of the object.

18. What is method overwriting in Perl?

  1. Filling up method with extra written data
  2. Methods that provide extra features
  3. A Feature that allows rewriting of methods in child class
  4. All of these

Answer: A Filling up method with extra written data

Explanation: Method overwriting in Perl is a feature using which we can rewrite the method in child class.

19. Method overwriting can be used to implement run time polymorphism?

  1. TRUE
  2. FALSE

Answer: A TRUE

Explanation: Run time polymorphism is implemented in Perl using method overwriting.

20. Which of these are valid type of inheritance in Perl?

  1. Multiple inheritance
  2. Multilevel inheritance
  3. Hierarchical inheritance
  4. All of these

Answer: D All of these

Explanation: Common types of inheritance in Perl are:

  • Simple inheritance
  • Multiple inheritance
  • Multilevel inheritance
  • Hierarchical inheritance

21. What is multiple inheritance in Perl?

  1. When more than two different inheritance takes place in a single program.
  2. When a class inherits more than two classes
  3. When two classes inherit properties from a single class
  4. None of these

Answer: B When a class inherits more than two classes

Explanation: In multiple inheritance, one class inherits more than two classes in Perl.

22. What is multilevel inheritance in Perl?

  1. A subclass of a class is inherited by another class
  2. A class inherits properties from multiple classes
  3. Multiple classes inherit properties from a class
  4. None of these

Answer: A A subclass of a class is inherited by another class

Explanation: In multilevel inheritance, a subclass of a class is inherited by another class in Perl.

23. What is polymorphism in Perl?

  1. Creating multiple constants with the same name
  2. Defining multiple methods under the same name
  3. Creating multiple variables with the same name
  4. All of these

Answer: D All of these

Explanation: Polymorphism in Perl is defining multiple methods under the same name.

24. What is encapsulation in Perl?

  1. Creating Arrays
  2. Wrapping up data and related methods to a single unit
  3. Creating separate structures storing values
  4. All of these

Answer: B Wrapping up data and related methods to a single unit

Explanation: Encapsulation is wrapping up data and related methods to a single unit in Perl.

25. Encapsulation is also known as?

  1. Polymorphism
  2. Method overloading
  3. Data hiding
  4. None of these

Answer: C Data hiding

Explanation: Data hiding in Perl is also known as Encapsulation.

26. Advantages of encapsulation are –

  1. Data hiding
  2. Reusability
  3. Ease of testing
  4. All of these

Answer: D All of these

Explanation: Advantages of Encapsulation are –

  • Data Hiding
  • Increasing Flexibility
  • Reusability
  • Testing code is easy

27. Which statement is used to enable strict mode in Perl?

  1. Strict mode;
  2. use strict;
  3. use strict mode;
  4. None of these

Answer: B use strict;

Explanation: The syntax to enable strict mode in Perl is,

Use strict

28. Is boolean type provided in Perl?

  1. Yes
  2. No

Answer: B No

Explanation: There is no boolean type in Perl.

29. What will be the output of the following Perl code?

$m = 2;

if ($m){
print “True”;
}
else{
print “False”;
}

  1. True
  2. False
  3. Error
  4. None of these

Answer: A True

30. Which of these is the ‘True’ value in Perl?

  1. “”
  2. 0
  3. 5
  4. All of these

Answer: C 5

Explanation: All value greater than 0 are true in Perl.

31. Which of the following is a type of operator in Perl?

  1. Arithmetic Operator
  2. Relational Operator
  3. Ternary Operator
  4. All of these

Answer: D All of these

Explanation: Types of operators:

  • Arithmetic Operator
  • Relation Operator
  • Logical Operator
  • Bitwise Operator
  • Assignment Operator
  • Ternary Operator

32. Logical operators in Perl are ___.

  1. Used to compare values
  2. Used to combine conditions
  3. Used to perform arithmetic operations
  4. None of these

Answer: B Used to combine conditions

Explanation: Logical operators in Perl are used to combine multiple conditions.

33. The result of the following operation is –

100 << 3
  1. 001
  2. 300
  3. 800
  4. Error

Answer: C 800

Explanation: The “<<” is a binary left shift operator, if left shifts the bits of the first operand, the second operand decides the number of places to shift.

34. Which of the following is a valid assignment operator in Perl?

  1. =
  2. ==
  3. +=
  4. %=

Answer: B ==

Explanation:

  • = is simple assignment operator
  • += is addition assignment operator
  • %= is remainder assignment operator

35. What will be the output of the following Perl code?

$val1 = 5;
$val2 = 10;

$result = $val1 == $val2 ? $val1 : $val2;

print “$result”

  1. 5
  2. 15
  3. 10
  4. 20

Answer: C 10

36. ‘x’ operator on string used to?

  1. Add x character to the string
  2. Repeat the given string multiple times
  3. Add two strings
  4. None of these

Answer: B Repeat the given string multiple times

Explanation: The “x” operator in Perl strings is used to repeat the given string multiple times.

37. Is auto increment/ decrement operator valid in Perl?

  1. Yes
  2. No

Answer: A Yes

Explanation: In Perl, auto increment / decrement operator are used to increase or decrease values.

38. What are ‘listary operators’ in Perl?

  1. Operator on collections
  2. Operators on integers
  3. Operators on the list of operators
  4. All of these

Answer: C Operators on the list of operators

Explanation: Listary operator is an operator that operates on a list of operands.

39. What is the correct operator precedence for the following operators?

    && , &, = , ->
  1. & , && , = , ->
  2. -> , & , && , =
  3. = , & , && , ->
  4. = , -> , && , &

Answer: B -> , & , && , =

40. Do we need to specify the data type of a variable in Perl?

  1. Yes
  2. No

Answer: B No

Explanation: In Perl, the data type declaration of variables is not required.

41. Which of these is a valid way to start a variable?

  1. $
  2. @
  3. %
  4. All of these

Answer: D All of these

Explanation: You can start a variable using $, @, % character.

42. Which of these is not a basic data type in Perl?

  1. Integer
  2. Arrays
  3. Scalars
  4. None of these

Answer: A Integer

Explanation: Perl in basic data types are:

  • Scalar variable
  • Array variable
  • Hash variable

43. Scalar variables in Perl are ___.

  1. Array values
  2. A Single unit of data
  3. String Values
  4. All of these

Answer: B A Single unit of data

Explanation: Scalar variables in Perl are a single unit of data. Different types of scalars in Perl are string, character, floating point, large group of string, webpage, etc.

44. Global scope variables can be used –

  1. Inside any function or block
  2. Inside a specific function
  3. Inside a specific block
  4. None of these

Answer: A Inside any function or block

Explanation: Global scoped variable is declared outside all blocks of code. The scope of this variable inside any function or block.

45. ‘Our’ keyword is used to ___.

  1. Create an alias to package
  2. Create a new variable
  3. Create a virtual variable
  4. None of these

Answer: A Create an alias to package

Explanation: The “Our” keyword is used to create an alias to package.

46. What is a module in Perl?

  1. Collection of related subroutines and variables
  2. Array of functions
  3. Collection of values of same type
  4. None of these

Answer: A Collection of related subroutines and variables

Explanation: A module in Perl is a collection consisting of variables and related subroutines.

47. Which statement in Perl is used to import a module?

  1. import module_name
  2. include module_name
  3. use module_name
  4. None of these

Answer: C use module_name

Explanation: The “use” keyword in Perl is used to import a module in Perl.

48. What is a number in Perl?

  1. Mathematical object for counting, measuring, and performing mathematical operations
  2. math module
  3. Non string type
  4. All of these

Answer: A Mathematical object for counting, measuring, and performing mathematical operations

Explanation: Number in Perl is a mathematical object for counting, measuring, and performing mathematical operations.

49. ‘%b’ in the Perl output statement used to?

  1. Print backspace character
  2. Print binary of a number
  3. Print the statement in bold in web
  4. None of these

Answer: B Print binary of a number

Explanation: The “%b” character sequence is used to print the number’s hexadecimal conversion.

50. Which escape sequence is used to print hexadecimal of a number in Perl?

  1. %h
  2. %b
  3. %hex
  4. %x

Answer: D %x

Explanation: The “%x” character sequence is used to print the number’s hexadecimal conversion.

51. What is a directory in Perl?

  1. A place to store values in the form of a list
  2. An array to string
  3. A data structure
  4. None of these

Answer: A A place to store values in the form of a list

Explanation: In Perl, Directory is a place to store values in the form of a list.

52. Which of the following operations can be performed on directories?

  1. Creating directory
  2. Closing directory
  3. Changing directory path
  4. All of these

Answer: D All of these

Explanation: Different operations that can be performed on a directory are:

  • Creating a new directory
  • Opening an existing directory
  • Reading contents of a directory
  • Changing a directory path
  • Closing a directory
  • Removing the directory

53. The chdir() function used to ___.

  1. Change directory
  2. Remove directory
  3. Create directory
  4. None of these

Answer: A Change directory

Explanation: The chdir() function used to change the current directory in Perl.

54. Which method in Perl is used to delete a directory?

  1. deldir
  2. rmdir
  3. cldir
  4. chdir

Answer: B rmdir

Explanation: In Perl, rmdir is used to delete a directory.

55. A group of statements that perform a specific task is known as ___.

  1. Function
  2. Subroutine
  3. Method
  4. All of these

Answer: D All of these

Explanation: A group of statements that perform a specific task is known as function or subroutine or method.

56. Which of these is a valid way to define a function in Perl?

  1. returntype function_name{
    }
  2. sub function_name{
    }
  3. function function_name{
    }
  4. None of these

Answer: B

sub function_name{
}

Explanation: The valid method to define a function in Perl,

sub function_name{	
}

57. Arguments in Perl are passed as ___.

  1. Values
  2. Strings
  3. Array
  4. All of these

Answer: C Array

Explanation: Arguments in Perl are passed as values, strings, array.

58. Is return type required for a subroutine in Perl?

  1. Yes
  2. No

Answer: B No

Explanation: No, the return type is required for a subroutine in Perl.

59. Is it possible to pass file handles to subroutines in Perl?

  1. Yes
  2. No

Answer: A Yes

Explanation: It is possible to pass file handles to subroutines in Perl.

60. Immutable parameters in Perl are?

  1. Special immutable string parameters passed to the function
  2. Values that cannot be modified within the function
  3. Values that can be modified within the function
  4. None of these

Answer: B Values that cannot be modified within the function

Explanation: Immutable parameters in Perl are values that cannot be modified within the function.

61. A built-in subroutine which is used inside the method is?

  1. Mutable parameter
  2. Trait
  3. Method
  4. All of these

Answer: B Trait

Explanation: Trait is a built-in subroutine which is used inside the method.

62. Which of the following is a trait in Perl?

  1. is cached
  2. is rw
  3. is copy
  4. All of these

Answer: D All of these

Explanation: Trait in Perl is:

  • is cached
  • is rw
  • is copy

63. What are reference in Perl?

  1. A way to access data with another variable
  2. Referring a function
  3. Class variable
  4. None of these

Answer: A A way to access data with another variable

Explanation: Reference in Perl is a way to access data with another variable.

64. The return() function in Perl is ___.

  1. a subroutine from return package
  2. return value at the end of subroutines
  3. return named subroutine
  4. None of these

Answer: B return value at the end of subroutines

Explanation: The return() function in Perl is used to return values at the end of subroutines.

65. List context of the returned value from a subroutine is extracted using ___.

  1. #
  2. $
  3. @
  4. None of these

Answer: C @

Explanation: The @ is used to return the list context of the returned value from a subroutine.

66. What is recursion in Perl?

  1. Mechanism of a function calling itself again from its body
  2. Looping over function with different values
  3. Calling overloaded function
  4. All of these

Answer: A Mechanism of a function calling itself again from its body

Explanation: Recursion is a mechanism of a function calling itself again from its body.

67. Which of the following methods is used to display expressions in Perl?

  1. cout()
  2. say()
  3. println()
  4. None of these

Answer: B say()

Explanation: The say() method is used to display expressions in Perl.

68. Automatic end of line is added using which statement?

  1. print()
  2. clear()
  3. say()
  4. All of these

Answer: C say()

Explanation: The say() method is used to display expressions in Perl. It automatically adds the end of line after print.

69. The print method in Perl return ___.

  1. boolean value
  2. string
  3. char
  4. None of these

Answer: A boolean value

Explanation: The return type of Perl method is boolean.

70. STDIN in Perl stands for ___.

  1. Standard input output stream
  2. STandarD INput
  3. Solo input
  4. None of these

Answer: B STandarD INput

Explanation: STDIN in Perl stands for STandarD INput.

71. Which of these is a decision-making statement in Perl?

  1. if
  2. unless
  3. if-else ladder
  4. All of these

Answer: D All of these

Explanation: Decision making statement in Perl are:

  • If
  • Else-if
  • Else-elsif
  • Unless
  • Unless-if
  • Unless-elsif

72. The code blocks unless the statement is executed when the condition is ___.

  1. True
  2. False

Answer: B False

Explanation: The code blocks unless the statement is executed when the condition is False.

73. Unless_elsif statement contains ___.

  1. elsif statement along with unless
  2. if nested inside unless
  3. unless nested inside elsif
  4. None of these

Answer: A elsif statement along with unless

Explanation: unless elsif statement has elseif statement working with unless.

74. Valid loops in Perl are ___.

  1. for
  2. foreach
  3. do while
  4. All of these

Answer: D All of these

Explanation: Valid loops in Perl are for, foreach, while, do while, until, nested loop.

75. foreach loop can iterate over __.

  1. List
  2. Integer
  3. Class
  4. None of these

Answer: A List

Explanation: Foreach loop can iterate over a list.

76. While in Perl is entry controlled?

  1. Yes
  2. No

Answer: A Yes

Explanation: While loop in Perl is entry controlled.

77. Until loop in Perl is ___.

  1. Opposite of while loop.
  2. Used to execute code when condition is false
  3. Entry controlled loop
  4. All of these

Answer: D All of these

Explanation: Until loop in Perl is an entry-controlled loop with acts just opposite to while loop i.e., the code inside the loop will run if the condition inside it is false.

78. What will be the output of the following Perl code?

$a = 8;

until ($a <= 7){
print “Value of a = $a\n”;
$a = $a – 1;
}

  1. Value of a = 8
  2. Infinite loop
  3. No run
  4. None

Answer: A Value of a = 8

79. What is a given-when statement in Perl?

  1. loop
  2. Multiway branch statement
  3. function
  4. None of these

Answer: B Multiway branch statement

Explanation: Given-when in Perl is a multiway branch statement.

80. Can a given-when statement be nested in Perl?

  1. Yes
  2. No

Answer: A Yes

Explanation: Perl allows the programmer to nest given-when statements too.

81. Is the goto statement in Perl used to ___.

  1. Iterate over statements
  2. Jump from anywhere to anywhere within the block
  3. Create an entry point in program
  4. None of these

Answer: B Jump from anywhere to anywhere within the block

Explanation: The goto statement in Perl is used to jump from anywhere to anywhere with the block of code.

82. Is the Redo operator in Perl used?

  1. Create a loop
  2. Jump the flow to the given label skipping the current block execution
  3. Repeat current block evaluation
  4. All of these

Answer: B Jump the flow to the given label skipping the current block execution

Explanation: The redo operator is used to Jump the flow to the given label skipping the current block execution.

83. Which keyword is used to make the current iteration last one?

  1. end
  2. exit
  3. last
  4. None of these

Answer: C last

Explanation: The last keyword in Perl can make the current iteration of the loop the last one.

84. Which of these is a data type in Perl?

  1. Scalars
  2. Array
  3. Hashes
  4. All of these

Answer: D All of these

Explanation: Data types in Perl are:

  • Scalar
  • Array
  • Hashes

85. Which of these is a type of the scalar in Perl?

  1. Array
  2. String
  3. Hash
  4. All of these

Answer: B String

Explanation: Scalar variables in Perl are a single unit of data. Different types of scalars in Perl are string, character, floating point, large group of string, webpage, etc.

86. The % sign in Perl is used to ___.

  1. Declare a hash
  2. Accessing a hash value
  3. Initialize a loop
  4. All of these

Answer: A Declare a hash

Explanation: Hash in Perl are declared using the % sign.

87. The elements of the array are ___.

  1. Number
  2. String
  3. Characters
  4. All of these

Answer: D All of these

Explanation: The elements of the array can be number, string, characters, etc.

88. Array in Perl created using?

  1. %
  2. @
  3. $
  4. None of these

Answer: B @

Explanation: Array declaration in Perl is done using @.

89. Which is a valid way to extract the size of an array in Perl?

  1. _len(@array_name)
  2. @array_name.length()
  3. $size = scalar @array_name
  4. All of these

Answer: C $size = scalar @array_name

Explanation: The valid way to extract the size of an array in Perl is:

    $size = scalar @array_name 

90. What is a hash in Perl?

  1. Set of key-value pair
  2. Collection storing scalar
  3. Collection sorting array
  4. None of these

Answer: A Set of key-value pair

Explanation: Hash in Perl is a set of key-value pairs.

91. Keys of the hash are extracted using?

  1. Index
  2. Using key function
  3. Converting to array
  4. None of these

Answer: B Using key function

Explanation: Keys of the hash are extracted using the key function.

92. What will be the output of the following Perl code?

%lang = (‘Perl’ => 4, ‘Python’ => 2, ‘Javascript’ => 5);
@arr = values %lang;
print @arr

  1. PerlPythonJavascript
  2. 245
  3. 425
  4. None of these

Answer: C 425

93. Operations of Perl hashes are ___.

  1. Accessing value
  2. Updating value
  3. Iteration
  4. All of these

Answer: D All of these

Explanation: Operations on Perl hashes are,

  • Accessing value
  • Updating value
  • Iteration

94. The $ in Perl is used to create ___.

  1. Hash
  2. Array
  3. Scalar
  4. All of these

Answer: C Scalar

Explanation: The $ in Perl is used to create scalar.

95. The ‘==’ operation is not valid on string in Perl?

  1. True
  2. False

Answer: A True

Explanation: The == operation in Perl is not a valid comparison operator on strings.

96. Is the Scalar keyword in Perl is used to?

  1. Create a scalar value
  2. Convert expression to scalar context
  3. Perform forceful evaluation to scalar
  4. All of these

Answer: D All of these

Explanation: Scalar keyword in Perl is used to,

  • Create a scalar value
  • Convert expression to scalar context
  • Perform forceful evaluation to scalar

97. Which of these types of string are interpolated?

  1. Quote less
  2. Single quoted
  3. Double quoted
  4. None of these

Answer: C Double quoted

Explanation: Double quoted string in Perl is interpolated.

98. The ‘It’ operator of string is used to ___.

  1. Concatenate string
  2. Check if the string to its left is stringwise less than string to its left
  3. Substitute text
  4. None of these

Answer: B Check if the string to its left is stringwise less than string to its left

Explanation: The ‘It’ operator of string is used to check if the string to its left is stringwise less that string to its left.

99. Length of string in Perl is calculated using ___.

  1. len()
  2. length()
  3. size()
  4. All of these

Answer: B length()

Explanation: The length of string in Perl is calculated using length() method.

100. Which module is required to perform excel operation in Perl?

  1. Excel::creator
  2. Sheets::manager
  3. Excel::Writer::XLSX
  4. None of these

Answer: C Excel::Writer::XLSX

Explanation: Module required to perform excel operation in Perl is,

Excel :: Writer :: XLSX

PERL objective questions with answers pdf download online exam test