Google News
logo
Perl - Quiz(MCQ)
A)
Tim O'Reilly
B)
Larry Wall
C)
Jimmy Wales
D)
James Gosling

Correct Answer :   Larry Wall


Explanation : In December 1987 American programmer and linguist Larry Wall first released Perl 1.0 for computers running the UNIX operating system.

A)
December 1961
B)
December 1969
C)
December 1978
D)
December 1987

Correct Answer :   December 1987


Explanation : Perl was developed by Larry Wall in December 1987 as a general-purpose Unix scripting language to make report processing easier.

A)
Array
B)
Hashes
C)
Scalar
D)
All of the above.

Correct Answer :   Scalar

A)
List
B)
Void
C)
Boolean
D)
Scalar

Correct Answer :   Boolean


Explanation : Boolean context is simply any place where an expression is being evaluated

A)
join EXPR, LIST
B)
sort EXPR, LIST
C)
split EXPR, LIST
D)
splice EXPR, LIST

Correct Answer :   join EXPR, LIST


Explanation : This function joins the separate strings of LIST into a single string with fields separated by the value of EXPR, and returns the string.

A)
seek
B)
getc
C)
close
D)
None of the above.

Correct Answer :   getc


Explanation : The getc function returns a single character from the specified FILEHANDLE, or STDIN if none is specified.

A)
local
B)
my
C)
state
D)
None of the above.

Correct Answer :   local


Explanation : The local is used when the current value of a variable must be visible to called subroutines.

A)
..
B)
--
C)
++
D)
->

Correct Answer :   ->


Explanation : -> − The arrow operator is mostly used in dereferencing a method or variable from an object or a class name.

A)
qq{ }
B)
qx{ }
C)
q{ }
D)
enclose{}

Correct Answer :   q{ }


Explanation : q{ } − Encloses a string with-in single quotes.

A)
values
B)
keys
C)
Both of the above.
D)
None of the above.

Correct Answer :   keys


Explanation : keys − You can get a list of all of the keys from a hash by using keys function.

A)
*
B)
**
C)
/
D)
%

Correct Answer :   **


Explanation : ** − Exponent − Performs exponential (power) calculation on operators.

A)
>
B)
>=
C)
<=
D)
<=>

Correct Answer :   >


Explanation : > − Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true.

A)
Perl's DBI package makes web-database integration easy.
B)
Perl can handle encrypted Web data, including e-commerce transactions.
C)
Perl is an interpreted language, which means that your code can be run as is, without a compilation stage that creates a non portable executable program.
D)
All of the above.

Correct Answer :   All of the above.

A)
Package
B)
PACKAGE
C)
_PACKAGE_
D)
None of the above.

Correct Answer :   _PACKAGE_


Explanation : _PACKAGE_  represents current package name.

A)
pop @ARRAY
B)
push @ARRAY, LIST
C)
shift @ARRAY
D)
unshift @ARRAY, LIST

Correct Answer :   shift @ARRAY


Explanation : shift @ARRAY − Shifts the first value of the array off and returns it, shortening the array by 1 and moving everything down.

A)
True
B)
False
C)
--
D)
--

Correct Answer :   True


Explanation : Parameters can be acessed inside the function using the special array @_. Thus the first argument to the function is in $_[0], the second is in $_[1], and so on.

A)
$ref = \$foo;
B)
$ref = \%ENV;
C)
$ref = \@ARGV;
D)
$ref = \&PrintHash;

Correct Answer :   $ref = \%ENV;


Explanation : You can create a reference for any hash by prefixing it with a backslash as follows - $ref = \%ENV;

A)
Lexical scoping is done with my operator.
B)
The my operator confines a variable to a particular region of code in which it can be used and accessed. Outside that region, this variable cannot be used or accessed.
C)
A lexical scope is usually a block of code with a set of braces around it, such as those defining the body of the subroutine or those marking the code blocks of if, while, for, foreach, and eval statements.
D)
All of the above.

Correct Answer :   All of the above.

A)
goto EXPR
B)
goto &NAME
C)
goto LABEL
D)
None of the above.

Correct Answer :   goto EXPR


Explanation : The goto EXPR form is just a generalization of goto LABEL. It expects the expression to return a label name and then jumps to that labeled statement.

A)
Using scalar context
B)
using sizeof operator
C)
Both (A) and (B)
D)
None of the above.

Correct Answer :   Using scalar context


Explanation : You can get the size − that is, the number of elements from a hash by using the scalar context on either keys or values.

A)
sed
B)
awk
C)
perl
D)
grep

Correct Answer :   perl


Explanation : A perl is the finest filter used on the UNIX system and is the finest of all (grep, sed, awk, tr). In fact, it combines the power of these. There is nothing can these filters can do and perl can’t.

A)
perl -i
B)
perl -e
C)
perl -el
D)
perl -ed

Correct Answer :   perl -e


Explanation : Unlike other filters, script errors are generated before the execution of perl script file. To check whether perl exist on our system or not use this simple command:

A)
.sh
B)
.gp
C)
.awk
D)
.pl

Correct Answer :   .pl


Explanation : perl programs are often very big, hence it is better to use .pl extension with perl program files.

A)
\d
B)
\n
C)
\s
D)
\w

Correct Answer :   \w


Explanation :

Perl offers some escaped characters to represent whitespace, digits and word boundaries. The most commonly used ones are:
\s - a whitespace character
\d - a digit
\w - a word character

A)
s
B)
tr
C)
str
D)
tr and s

Correct Answer :   tr and s


Explanation : The s and tr functions handle all substitutions in perl. The s command is used in same way as it was used in sed while tr is used translating the characters in the same way as the UNIX tr command does.

A)
reverse
B)
rev
C)
split
D)
substr

Correct Answer :   reverse


Explanation :

The reverse function, which can operate on strings as well as arrays is used to reverse the characters in a string and return the reversed string. For example,
$x= “abcd” ;
print reverse($x) ;       / prints dcba

A)
cut
B)
split
C)
chop
D)
erase

Correct Answer :   chop


Explanation : In many conditions, we may need to chop the last character –especially when there is a newline character. For this purpose, chop function is used.

A)
character
B)
number
C)
boolean value
D)
floating point number

Correct Answer :   number


Explanation : There are some attributes which we should keep in mind while using perl. One of which is, when we use string for numerical comparison or computation, perl immediately converts it into a number.

A)
0
B)
1
C)
NULL
D)
garbage

Correct Answer :   0


Explanation : When a variable is undefined, it is assumed to be a NULL string and NULL string is numerically zero.

A)
.
B)
/
C)
_
D)
\\

Correct Answer :   .


Explanation :

Like in shell, concatenation is performed by placing two variables side by side. This case is not followed with perl. Rather perl uses . (dot) operator for concatenating two variables. For example,
$ perl  -e  '$x="FreeTime" ; $y="Learning" ; print($x . $y);'
FreeTimeLearning

A)
.
B)
/
C)
\\
D)
x

Correct Answer :   x


Explanation :

 perl uses the x operator to repeat a string. For example, the following command will print * 10 times;
$ perl  -e  ‘print “*” x 10 ;’
**********

A)
len
B)
split
C)
length
D)
string

Correct Answer :   length


Explanation :

The length function is used by perl to return the length of any string. For example,
$x= “Srinivas”;
print length($x);       // prints 8

A)
index
B)
substr
C)
string
D)
length

Correct Answer :   substr


Explanation :

The substr function extracts a particular substring from a string based on the value of specified indices. For example,
$x= “abcdefghijklm”
$y= substr( $x, -3,2);   // extracts two characters from the third position on the right side
print “$y”;             // prints kl

34 .
What is the syntax to create multiline comments in Perl?
A)
#begin
#cut
B)
=begin
=cut
C)
=start
=end
D)
None of the above

Correct Answer :  

=begin
=cut


Explaination :

The syntax for creating a multiline comment in Perl is : 
=begin
=cut

A)
Support closures
B)
It is interpreted language
C)
No main() [driver] function
D)
None of the above

Correct Answer :   None of the above


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.

A)
package class_name
B)
class class_name
C)
new class class_name
D)
new package class_name

Correct Answer :   package class_name


Explanation :

The correct syntax for creating a class in Perl is : package class_name

A)
Variable
B)
Destructor
C)
Constructor
D)
All of the above

Correct Answer :   All of the above


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

A)
new object_name = class_name()
B)
var object_name = new class_name()
C)
my object_name = new class_name()
D)
None of the above

Correct Answer :   my object_name = new class_name()


Explanation :

The correct syntax for creating an object in Perl is : my object_name = new class_name()

A)
Virtual method
B)
Constant method
C)
Static method
D)
All of the Above

Correct Answer :   Constant method


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

A)
Called at the start of the program
B)
Used for cleanup of reference of objects
C)
Not a program
D)
All of the above

Correct Answer :   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.

A)
Filling up method with extra written data
B)
Methods that provide extra features
C)
A Feature that allows rewriting of methods in child class
D)
All of the above

Correct Answer :   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.

A)
Simple inheritance
B)
Multilevel inheritance
C)
Hierarchical inheritance
D)
All of the Above

Correct Answer :   All of the Above


Explanation :

Common types of inheritance in Perl are:
 
Simple inheritance
Multiple inheritance
Multilevel inheritance
Hierarchical inheritance

A)
Excel::creator
B)
Sheets::manager
C)
Excel::Writer::XLSX
D)
None of the above

Correct Answer :   Excel::Writer::XLSX


Explanation :

Module required to perform excel operation in Perl is : Excel :: Writer :: XLSX

A)
len()
B)
size()
C)
len_size()
D)
length()

Correct Answer :   length()


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

A)
Concatenate string
B)
Substitute text
C)
Check if the string to its left is stringwise less than string to its left
D)
None of the above

Correct Answer :   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.

A)
True
B)
False
C)
--
D)
--

Correct Answer :   True


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

47 .
What will be the output of the following Perl code?
%lang = ('Perl' => 4, 'Python' => 2, 'Javascript' => 5);
@arr = values %lang;
print @arr
A)
245
B)
425
C)
PerlPythonJavascript
D)
None of the above

Correct Answer :   425

A)
Collection sorting array
B)
Set of key-value pair
C)
Collection storing scalar
D)
None of the above

Correct Answer :   Set of key-value pair


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

A)
_len(@array_name)
B)
@array_name.length()
C)
$size = scalar @array_name
D)
All of the above

Correct Answer :   $size = scalar @array_name


Explanation :

The valid way to extract the size of an array in Perl is : $size = scalar @array_name 

A)
end
B)
exit
C)
Both (A) and (B)
D)
last

Correct Answer :   last


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

A)
Create a loop
B)
Repeat current block evaluation
C)
Jump the flow to the given label skipping the current block execution
D)
All of the above

Correct Answer :   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.

A)
Iterate over statements
B)
Create an entry point in program
C)
Jump from anywhere to anywhere within the block
D)
None of the above

Correct Answer :   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.

A)
Loop
B)
String
C)
Function
D)
Multiway branch statement

Correct Answer :   Multiway branch statement


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

54 .
What will be the output of the following Perl code?
$a = 8;

until ($a <= 7){
    print "Value of a = $a\n";
    $a = $a - 1;
}
A)
Value of a = 8
B)
Infinite loop
C)
Code Error
D)
None of the above

Correct Answer :   Value of a = 8

A)
for
B)
foreach
C)
do while
D)
All of the above

Correct Answer :   All of the above


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

A)
if nested inside unless
B)
elsif statement along with unless
C)
unless nested inside elsif
D)
None of the above

Correct Answer :   elsif statement along with unless


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

A)
STandarD INput
B)
Simple Date Input
C)
Standard input output stream
D)
None of the Above

Correct Answer :   STandarD INput

A)
print()
B)
clear()
C)
say()
D)
loop()

Correct Answer :   say()


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

A)
return named subroutine
B)
return value at the end of subroutines
C)
a subroutine from return package
D)
None of the above

Correct Answer :   return value at the end of subroutines


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

A)
Trait
B)
Method
C)
Mutable parameter
D)
All of the above

Correct Answer :   Trait


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

A)
Values that cannot be modified within the function
B)
Values that can be modified within the function
C)
Special immutable string parameters passed to the function
D)
None of the above

Correct Answer :   Values that cannot be modified within the function


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

A)
Strings
B)
Values
C)
Both (A) and (B)
D)
Array

Correct Answer :   Array

A)
function function_name{ }
B)
returntype function_name{ }
C)
sub function_name{ }
D)
None of the Above

Correct Answer :   sub function_name{ }


Explanation :

The valid method to define a function in Perl : sub function_name{}

A)
Method
B)
Function
C)
Subroutine
D)
All of the above

Correct Answer :   All of the above


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

A)
cldir
B)
rmdir
C)
chdir
D)
deldir

Correct Answer :   rmdir


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

A)
Change directory
B)
Create directory
C)
Remove directory
D)
None of the above

Correct Answer :   Change directory


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

A)
A data structure
B)
An array to string
C)
A place to store values in the form of a list
D)
None of the above

Correct Answer :   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.

A)
%b
B)
%x
C)
%h
D)
%hex

Correct Answer :   %x


Explanation : The "%x" character sequence is used to print the number's hexadecimal conversion.

A)
use module_name
B)
import module_name
C)
include module_name
D)
None of the above

Correct Answer :   use module_name


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

A)
Create a new array
B)
Create a new variable
C)
Create a virtual variable
D)
Create an alias to package

Correct Answer :   Create an alias to package


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

A)
Inside a specific block
B)
Inside any function or block
C)
Inside a specific function
D)
None of the above

Correct Answer :   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.

A)
Array values
B)
String Values
C)
String_len Values
D)
A Single unit of data

Correct Answer :   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.

A)
Arrays
B)
Scalars
C)
Integer
D)
None of the above

Correct Answer :   Integer


Explanation :

Perl in basic data types are :
 
* Scalar variable
* Array variable
* Hash variable

A)
When a class inherits more than two classes
B)
When two classes inherit properties from a single class
C)
When more than two different inheritance takes place in a single program.
D)
None of the above

Correct Answer :   When a class inherits more than two classes


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

A)
Multiple classes inherit properties from a class
B)
A subclass of a class is inherited by another class
C)
A class inherits properties from multiple classes
D)
None of the above

Correct Answer :   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.

A)
Creating multiple variables with the same name
B)
Creating multiple constants with the same name
C)
Defining multiple methods under the same name
D)
All of the Above

Correct Answer :   All of the Above


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

A)
Creating Arrays
B)
Creating separate structures storing values
C)
Wrapping up data and related methods to a single unit
D)
All of the above

Correct Answer :   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.

A)
Polymorphism
B)
Data hiding
C)
Method overriding
D)
Method overloading

Correct Answer :   Data hiding


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

A)
Reusability
B)
Data hiding
C)
Ease of testing
D)
All of the Above

Correct Answer :   All of the Above


Explanation :

Advantages of Encapsulation are :
 
* Reusability
*
Data Hiding
* Increasing Flexibility
* Testing code is easy

A)
Use strict;
B)
Strict mode;
C)
Use strict mode;
D)
None of the above

Correct Answer :   use strict;


Explanation :

The syntax to enable strict mode in Perl is : Use strict

A)
Arithmetic Operator
B)
Logical Operator
C)
Assignment Operator
D)
All of the above

Correct Answer :   All of the above


Explanation :

Types of operators :
 
* Arithmetic Operator
* Relation Operator
* Logical Operator
* Bitwise Operator
* Assignment Operator
* Ternary Operator

A)
Used to compare values
B)
Used to perform arithmetic operations
C)
Used to combine conditions
D)
None of the above

Correct Answer :   Used to combine conditions


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

83 .
The result of the following operation is -  100 << 3
A)
001
B)
800
C)
300
D)
None of the above

Correct Answer :   800


Explaination :

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.
 

A)
=
B)
+=
C)
==
D)
%=

Correct Answer :   ==


Explanation :

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

85 .
What will be the output of the following Perl code?
$val1 = 5;
$val2 = 10;

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

print "$result"
A)
1
B)
2
C)
5
D)
10

Correct Answer :   10

A)
Add two strings
B)
Add x character to the string
C)
Both (A) and (B)
D)
Repeat the given string multiple times

Correct Answer :   Repeat the given string multiple times


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

A)
Operators on integers
B)
Operator on collections
C)
Operators on the list of operators
D)
All of the above

Correct Answer :   Operators on the list of operators


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

88 .
What is the correct operator precedence for the following operators?
&& , &, = , ->
A)
-> , & , && , =
B)
= , & , && , ->
C)
= , -> , && , &
D)
& , && , = , ->

Correct Answer :   -> , & , && , =

A)
Assignment Operator
B)
Arithematic Operator
C)
Comparision Operator
D)
Increment/Decrement Operator

Correct Answer :   Assignment Operator


Explanation : "+=" known as "Assignment operator" in Perl.

A)
(.)
B)
(x)
C)
($)
D)
(++)

Correct Answer :   (x)