Home »
MCQs
Perl Programming MCQs
Perl is a general-purpose, high-level interpreted, and dynamic programming language. Perl programming language was developed by Larry Wall, in 1987. There is no official Full form of Perl, but still, the most used expansion is "Practical Extraction and Reporting Language".
Perl Programming MCQs: This section contains multiple-choice questions and answers on the Perl programming language. It will help the students to test their skills and prepare well for their exams.
List of Perl Programming MCQs
1. Perl Programming language is ___?
- General purpose programming language
- Dynamic programming language
- High-level interpreted programming language
- All of these
Answer: D) All of these
Explanation:
Perl is a general-purpose, high-level interpreted, and dynamic programming language.
Discuss this Question
2. The creator of Perl programming language is ___.
- James Gosling
- Brendan Eich
- Larry Wall
- 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.
Discuss this Question
3. The year in which Perl was launched?
- 1986
- 1987
- 1988
- 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.
Discuss this Question
4. What are the benefits of the Perl programming language?
- Easy to learn
- Text Processing
- Easy to be embedded on web pages
- 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
Discuss this Question
5. What is the file extension for the Perl program?
- .pl
- .perl
- .prl
- None of these
Answer: A) .pl
Explanation:
The extension .pl is used to create a Perl file.
Discuss this Question
6. What is the syntax to create multiline comments in Perl?
- =start
=end
- #begin
#cut
- =begin
=cut
- None of these
Answer: C) =begin
=cut
Explanation:
The syntax for creating a multiline comment in Perl is:
=begin
=cut
Discuss this Question
7. What are the disadvantages of Perl over C/C++?
- No main() [driver] function
- Support closures
- It is interpreted language
- 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.
Discuss this Question
8. Which of the following is not a concept of OOP?
- Encapsulation
- Class
- Abstraction
- None of these
Answer: D) None of these
Explanation:
The concepts of OOPs are:
- Class
- Object
- Method
- Polymorphism
- Inheritance
- Encapsulation
- Abstraction
Discuss this Question
9. Method in Perl is?
- Time savers
- User to reuse code w/o retyping the code
- Collections of statement that perform specific tasks
- 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.
Discuss this Question
10. Is the following statement correct for Perl?
"Data Abstraction displays only the essential details to the user"
- TRUE
- 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.
Discuss this Question
11. What is the correct syntax for defining a class in Perl?
- package class_name
- class class_name
- new class class_name
- new package class_name
Answer: A) package class_name
Explanation:
The correct syntax for creating a class in Perl is:
package class_name
Discuss this Question
12. Object in Perl an instance of a class?
- TRUE
- FALSE
Answer: A) TRUE
Explanation:
Objects are instances of class.
Discuss this Question
13. What is called when an object is created in Perl?
- Destructor
- Constructor
- Variable
- 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.
Discuss this Question
14. What is the correct syntax for creating a new object in Perl?
- var object_name = new class_name()
- new object_name = class_name()
- my object_name = new class_name()
- 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()
Discuss this Question
15. Which of these is not a type of method in Perl?
- Static method
- Constant method
- Virtual method
- All of these
Answer: B) Constant method
Explanation:
Virtual methods and static methods are valid types of methods in Perl.
Discuss this Question
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();
- 15
- 15.00
- 14.5714285714286
- None of these
Answer: C) 14.5714285714286
Discuss this Question
17. Destructor's in Perl are ___.
- Used for cleanup of reference of objects
- Called at the start of the program
- Not a program
- 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.
Discuss this Question
18. What is method overwriting in Perl?
- Filling up method with extra written data
- Methods that provide extra features
- A Feature that allows rewriting of methods in child class
- 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.
Discuss this Question
19. Method overwriting can be used to implement run time polymorphism?
- TRUE
- FALSE
Answer: A) TRUE
Explanation:
Run time polymorphism is implemented in Perl using method overwriting.
Discuss this Question
20. Which of these are valid type of inheritance in Perl?
- Multiple inheritance
- Multilevel inheritance
- Hierarchical inheritance
- All of these
Answer: D) All of these
Explanation:
Common types of inheritance in Perl are:
- Simple inheritance
- Multiple inheritance
- Multilevel inheritance
- Hierarchical inheritance
Discuss this Question
21. What is multiple inheritance in Perl?
- When more than two different inheritance takes place in a single program.
- When a class inherits more than two classes
- When two classes inherit properties from a single class
- 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.
Discuss this Question
22. What is multilevel inheritance in Perl?
- A subclass of a class is inherited by another class
- A class inherits properties from multiple classes
- Multiple classes inherit properties from a class
- 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.
Discuss this Question
23. What is polymorphism in Perl?
- Creating multiple constants with the same name
- Defining multiple methods under the same name
- Creating multiple variables with the same name
- All of these
Answer: D) All of these
Explanation:
Polymorphism in Perl is defining multiple methods under the same name.
Discuss this Question
24. What is encapsulation in Perl?
- Creating Arrays
- Wrapping up data and related methods to a single unit
- Creating separate structures storing values
- 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.
Discuss this Question
25. Encapsulation is also known as?
- Polymorphism
- Method overloading
- Data hiding
- None of these
Answer: C) Data hiding
Explanation:
Data hiding in Perl is also known as Encapsulation.
Discuss this Question
26. Advantages of encapsulation are -
- Data hiding
- Reusability
- Ease of testing
- All of these
Answer: D) All of these
Explanation:
Advantages of Encapsulation are -
- Data Hiding
- Increasing Flexibility
- Reusability
- Testing code is easy
Discuss this Question
27. Which statement is used to enable strict mode in Perl?
- Strict mode;
- use strict;
- use strict mode;
- None of these
Answer: B) use strict;
Explanation:
The syntax to enable strict mode in Perl is,
Use strict
Discuss this Question
28. Is boolean type provided in Perl?
- Yes
- No
Answer: B) No
Explanation:
There is no boolean type in Perl.
Discuss this Question
29. What will be the output of the following Perl code?
$m = 2;
if ($m){
print "True";
}
else{
print "False";
}
- True
- False
- Error
- None of these
Answer: A) True
Discuss this Question
30. Which of these is the 'True' value in Perl?
- ""
- 0
- 5
- All of these
Answer: C) 5
Explanation:
All value greater than 0 are true in Perl.
Discuss this Question
31. Which of the following is a type of operator in Perl?
- Arithmetic Operator
- Relational Operator
- Ternary Operator
- All of these
Answer: D) All of these
Explanation:
Types of operators:
- Arithmetic Operator
- Relation Operator
- Logical Operator
- Bitwise Operator
- Assignment Operator
- Ternary Operator
Discuss this Question
32. Logical operators in Perl are ___.
- Used to compare values
- Used to combine conditions
- Used to perform arithmetic operations
- None of these
Answer: B) Used to combine conditions
Explanation:
Logical operators in Perl are used to combine multiple conditions.
Discuss this Question
33. The result of the following operation is -
100 << 3
- 001
- 300
- 800
- 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.
Discuss this Question
34. Which of the following is a valid assignment operator in Perl?
- =
- ==
- +=
- %=
Answer: B) ==
Explanation:
- = is simple assignment operator
- += is addition assignment operator
- %= is remainder assignment operator
Discuss this Question
35. What will be the output of the following Perl code?
$val1 = 5;
$val2 = 10;
$result = $val1 == $val2 ? $val1 : $val2;
print "$result"
- 5
- 15
- 10
- 20
Answer: C) 10
Discuss this Question
36. 'x' operator on string used to?
- Add x character to the string
- Repeat the given string multiple times
- Add two strings
- 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.
Discuss this Question
37. Is auto increment/ decrement operator valid in Perl?
- Yes
- No
Answer: A) Yes
Explanation:
In Perl, auto increment / decrement operator are used to increase or decrease values.
Discuss this Question
38. What are 'listary operators' in Perl?
- Operator on collections
- Operators on integers
- Operators on the list of operators
- All of these
Answer: C) Operators on the list of operators
Explanation:
Listary operator is an operator that operates on a list of operands.
Discuss this Question
39. What is the correct operator precedence for the following operators?
&& , &, = , ->
- & , && , = , ->
- -> , & , && , =
- = , & , && , ->
- = , -> , && , &
Answer: B) -> , & , && , =
Discuss this Question
40. Do we need to specify the data type of a variable in Perl?
- Yes
- No
Answer: B) No
Explanation:
In Perl, the data type declaration of variables is not required.
Discuss this Question
41. Which of these is a valid way to start a variable?
- $
- @
- %
- All of these
Answer: D) All of these
Explanation:
You can start a variable using $, @, % character.
Discuss this Question
42. Which of these is not a basic data type in Perl?
- Integer
- Arrays
- Scalars
- None of these
Answer: A) Integer
Explanation:
Perl in basic data types are:
- Scalar variable
- Array variable
- Hash variable
Discuss this Question
43. Scalar variables in Perl are ___.
- Array values
- A Single unit of data
- String Values
- 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.
Discuss this Question
44. Global scope variables can be used -
- Inside any function or block
- Inside a specific function
- Inside a specific block
- 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.
Discuss this Question
45. 'Our' keyword is used to ___.
- Create an alias to package
- Create a new variable
- Create a virtual variable
- None of these
Answer: A) Create an alias to package
Explanation:
The "Our" keyword is used to create an alias to package.
Discuss this Question
46. What is a module in Perl?
- Collection of related subroutines and variables
- Array of functions
- Collection of values of same type
- 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.
Discuss this Question
47. Which statement in Perl is used to import a module?
- import module_name
- include module_name
- use module_name
- None of these
Answer: C) use module_name
Explanation:
The "use" keyword in Perl is used to import a module in Perl.
Discuss this Question
48. What is a number in Perl?
- Mathematical object for counting, measuring, and performing mathematical operations
- math module
- Non string type
- 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.
Discuss this Question
49. '%b' in the Perl output statement used to?
- Print backspace character
- Print binary of a number
- Print the statement in bold in web
- None of these
Answer: B) Print binary of a number
Explanation:
The "%b" character sequence is used to print the number's hexadecimal conversion.
Discuss this Question
50. Which escape sequence is used to print hexadecimal of a number in Perl?
- %h
- %b
- %hex
- %x
Answer: D) %x
Explanation:
The "%x" character sequence is used to print the number's hexadecimal conversion.
Discuss this Question
51. What is a directory in Perl?
- A place to store values in the form of a list
- An array to string
- A data structure
- 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.
Discuss this Question
52. Which of the following operations can be performed on directories?
- Creating directory
- Closing directory
- Changing directory path
- 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
Discuss this Question
53. The chdir() function used to ___.
- Change directory
- Remove directory
- Create directory
- None of these
Answer: A) Change directory
Explanation:
The chdir() function used to change the current directory in Perl.
Discuss this Question
54. Which method in Perl is used to delete a directory?
- deldir
- rmdir
- cldir
- chdir
Answer: B) rmdir
Explanation:
In Perl, rmdir is used to delete a directory.
Discuss this Question
55. A group of statements that perform a specific task is known as ___.
- Function
- Subroutine
- Method
- 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.
Discuss this Question
56. Which of these is a valid way to define a function in Perl?
- returntype function_name{
}
- sub function_name{
}
- function function_name{
}
- None of these
Answer: B)
sub function_name{
}
Explanation:
The valid method to define a function in Perl,
sub function_name{
}
Discuss this Question
57. Arguments in Perl are passed as ___.
- Values
- Strings
- Array
- All of these
Answer: C) Array
Explanation:
Arguments in Perl are passed as values, strings, array.
Discuss this Question
58. Is return type required for a subroutine in Perl?
- Yes
- No
Answer: B) No
Explanation:
No, the return type is required for a subroutine in Perl.
Discuss this Question
59. Is it possible to pass file handles to subroutines in Perl?
- Yes
- No
Answer: A) Yes
Explanation:
It is possible to pass file handles to subroutines in Perl.
Discuss this Question
60. Immutable parameters in Perl are?
- Special immutable string parameters passed to the function
- Values that cannot be modified within the function
- Values that can be modified within the function
- 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.
Discuss this Question
61. A built-in subroutine which is used inside the method is?
- Mutable parameter
- Trait
- Method
- All of these
Answer: B) Trait
Explanation:
Trait is a built-in subroutine which is used inside the method.
Discuss this Question
62. Which of the following is a trait in Perl?
- is cached
- is rw
- is copy
- All of these
Answer: D) All of these
Explanation:
Trait in Perl is:
Discuss this Question
63. What are reference in Perl?
- A way to access data with another variable
- Referring a function
- Class variable
- 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.
Discuss this Question
64. The return() function in Perl is ___.
- a subroutine from return package
- return value at the end of subroutines
- return named subroutine
- 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.
Discuss this Question
65. List context of the returned value from a subroutine is extracted using ___.
- #
- $
- @
- None of these
Answer: C) @
Explanation:
The @ is used to return the list context of the returned value from a subroutine.
Discuss this Question
66. What is recursion in Perl?
- Mechanism of a function calling itself again from its body
- Looping over function with different values
- Calling overloaded function
- 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.
Discuss this Question
67. Which of the following methods is used to display expressions in Perl?
- cout()
- say()
- println()
- None of these
Answer: B) say()
Explanation:
The say() method is used to display expressions in Perl.
Discuss this Question
68. Automatic end of line is added using which statement?
- print()
- clear()
- say()
- 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.
Discuss this Question
69. The print method in Perl return ___.
- boolean value
- string
- char
- None of these
Answer: A) boolean value
Explanation:
The return type of Perl method is boolean.
Discuss this Question
70. STDIN in Perl stands for ___.
- Standard input output stream
- STandarD INput
- Solo input
- None of these
Answer: B) STandarD INput
Explanation:
STDIN in Perl stands for STandarD INput.
Discuss this Question
71. Which of these is a decision-making statement in Perl?
- if
- unless
- if-else ladder
- 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
Discuss this Question
72. The code blocks unless the statement is executed when the condition is ___.
- True
- False
Answer: B) False
Explanation:
The code blocks unless the statement is executed when the condition is False.
Discuss this Question
73. Unless_elsif statement contains ___.
- elsif statement along with unless
- if nested inside unless
- unless nested inside elsif
- None of these
Answer: A) elsif statement along with unless
Explanation:
unless elsif statement has elseif statement working with unless.
Discuss this Question
74. Valid loops in Perl are ___.
- for
- foreach
- do while
- All of these
Answer: D) All of these
Explanation:
Valid loops in Perl are for, foreach, while, do while, until, nested loop.
Discuss this Question
75. foreach loop can iterate over __.
- List
- Integer
- Class
- None of these
Answer: A) List
Explanation:
Foreach loop can iterate over a list.
Discuss this Question
76. While in Perl is entry controlled?
- Yes
- No
Answer: A) Yes
Explanation:
While loop in Perl is entry controlled.
Discuss this Question
77. Until loop in Perl is ___.
- Opposite of while loop.
- Used to execute code when condition is false
- Entry controlled loop
- 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.
Discuss this Question
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;
}
- Value of a = 8
- Infinite loop
- No run
- None
Answer: A) Value of a = 8
Discuss this Question
79. What is a given-when statement in Perl?
- loop
- Multiway branch statement
- function
- None of these
Answer: B) Multiway branch statement
Explanation:
Given-when in Perl is a multiway branch statement.
Discuss this Question
80. Can a given-when statement be nested in Perl?
- Yes
- No
Answer: A) Yes
Explanation:
Perl allows the programmer to nest given-when statements too.
Discuss this Question
81. Is the goto statement in Perl used to ___.
- Iterate over statements
- Jump from anywhere to anywhere within the block
- Create an entry point in program
- 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.
Discuss this Question
82. Is the Redo operator in Perl used?
- Create a loop
- Jump the flow to the given label skipping the current block execution
- Repeat current block evaluation
- 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.
Discuss this Question
83. Which keyword is used to make the current iteration last one?
- end
- exit
- last
- None of these
Answer: C) last
Explanation:
The last keyword in Perl can make the current iteration of the loop the last one.
Discuss this Question
84. Which of these is a data type in Perl?
- Scalars
- Array
- Hashes
- All of these
Answer: D) All of these
Explanation:
Data types in Perl are:
Discuss this Question
85. Which of these is a type of the scalar in Perl?
- Array
- String
- Hash
- 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.
Discuss this Question
86. The % sign in Perl is used to ___.
- Declare a hash
- Accessing a hash value
- Initialize a loop
- All of these
Answer: A) Declare a hash
Explanation:
Hash in Perl are declared using the % sign.
Discuss this Question
87. The elements of the array are ___.
- Number
- String
- Characters
- All of these
Answer: D) All of these
Explanation:
The elements of the array can be number, string, characters, etc.
Discuss this Question
88. Array in Perl created using?
- %
- @
- $
- None of these
Answer: B) @
Explanation:
Array declaration in Perl is done using @.
Discuss this Question
89. Which is a valid way to extract the size of an array in Perl?
- _len(@array_name)
- @array_name.length()
- $size = scalar @array_name
- 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
Discuss this Question
90. What is a hash in Perl?
- Set of key-value pair
- Collection storing scalar
- Collection sorting array
- None of these
Answer: A) Set of key-value pair
Explanation:
Hash in Perl is a set of key-value pairs.
Discuss this Question
91. Keys of the hash are extracted using?
- Index
- Using key function
- Converting to array
- None of these
Answer: B) Using key function
Explanation:
Keys of the hash are extracted using the key function.
Discuss this Question
92. What will be the output of the following Perl code?
%lang = ('Perl' => 4, 'Python' => 2, 'Javascript' => 5);
@arr = values %lang;
print @arr
- PerlPythonJavascript
- 245
- 425
- None of these
Answer: C) 425
Discuss this Question
93. Operations of Perl hashes are ___.
- Accessing value
- Updating value
- Iteration
- All of these
Answer: D) All of these
Explanation:
Operations on Perl hashes are,
- Accessing value
- Updating value
- Iteration
Discuss this Question
94. The $ in Perl is used to create ___.
- Hash
- Array
- Scalar
- All of these
Answer: C) Scalar
Explanation:
The $ in Perl is used to create scalar.
Discuss this Question
95. The '==' operation is not valid on string in Perl?
- True
- False
Answer: A) True
Explanation:
The == operation in Perl is not a valid comparison operator on strings.
Discuss this Question
96. Is the Scalar keyword in Perl is used to?
- Create a scalar value
- Convert expression to scalar context
- Perform forceful evaluation to scalar
- 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
Discuss this Question
97. Which of these types of string are interpolated?
- Quote less
- Single quoted
- Double quoted
- None of these
Answer: C) Double quoted
Explanation:
Double quoted string in Perl is interpolated.
Discuss this Question
98. The 'It' operator of string is used to ___.
- Concatenate string
- Check if the string to its left is stringwise less than string to its left
- Substitute text
- 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.
Discuss this Question
99. Length of string in Perl is calculated using ___.
- len()
- length()
- size()
- All of these
Answer: B) length()
Explanation:
The length of string in Perl is calculated using length() method.
Discuss this Question
100. Which module is required to perform excel operation in Perl?
- Excel::creator
- Sheets::manager
- Excel::Writer::XLSX
- None of these
Answer: C) Excel::Writer::XLSX
Explanation:
Module required to perform excel operation in Perl is,
Excel :: Writer :: XLSX
Discuss this Question