Perl MCQ Banner

Perl Multiple Choice Questions (MCQs) and Answers

Master Perl with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of Perl. Begin your placement preparation journey now!

Q91

Q91 Why might sorting a hash using sort %hash cause unexpected results?

A

Hashes are unordered

B

Sort cannot be used on hashes

C

Sort only works on arrays

D

Hashes must be converted to arrays first

Q92

Q92 What keyword is used to import a Perl module?

A

import

B

use

C

require

D

include

Q93

Q93 What is the purpose of the require function in Perl?

A

Loads a module at compile time

B

Loads a module at runtime

C

Defines a package

D

Removes a module

Q94

Q94 What is the difference between use and require in Perl?

A

use loads at runtime, require loads at compile time

B

Both load modules at runtime

C

use loads at compile time, require loads at runtime

D

require can only be used for built-in modules

Q95

Q95 What is the purpose of the @INC array in Perl?

A

Stores imported variables

B

Contains paths to module directories

C

Defines function names

D

Lists all installed modules

Q96

Q96 How do you define a package in Perl?

A

package ModuleName;

B

module ModuleName;

C

define ModuleName;

D

include ModuleName;

Q97

Q97 What does the following Perl statement do?
use strict;

A

Enables strict mode for variable declarations

B

Turns off warnings

C

Defines a new package

D

Includes external modules

Q98

Q98 What is the purpose of Exporter in Perl modules?

A

Allows functions to be exported from a module

B

Defines private functions

C

Deletes functions from a module

D

Restricts module access

Q99

Q99 How do you correctly define and export a function in a Perl module?

A

our @EXPORT = ('function_name');

B

export function_name();

C

import function_name();

D

define function_name();

Q100

Q100 What is the correct way to include a module from a custom path?

A

use lib '/path/to/module';

B

require '/path/to/module';

C

include '/path/to/module';

D

import '/path/to/module';

Q101

Q101 Why might a Perl script fail with "Can't locate module in @INC"?

A

The module does not exist

B

The module is in an unlisted directory

C

Incorrect function usage

D

The module is already loaded

Q102

Q102 Why does use MyModule; sometimes fail even if the module exists?

A

The module is not compiled

B

The module does not have a .pm extension

C

The module does not return a true value

D

The module is too large

Q103

Q103 What might cause require to fail when loading a module?

A

The module is already in memory

B

The module lacks a valid package declaration

C

The module is case-sensitive in filename

D

Perl does not support require

Q104

Q104 What keyword is used to define a class in Perl?

A

class

B

package

C

module

D

object

Q105

Q105 How is an object typically created in Perl?

A

new ClassName;

B

ClassName->new();

C

create ClassName();

D

ClassName->create();

Q106

Q106 What is the significance of the bless function in Perl?

A

It converts a scalar into an object

B

It loads a module

C

It creates a new package

D

It deletes an object

Q107

Q107 How does Perl support inheritance in object-oriented programming?

A

Using extends

B

Using @ISA array

C

Using super

D

Using inherit

Q108

Q108 What does the following Perl code do?
sub new { my $class = shift; my $self = {}; bless $self, $class; return $self; }

A

Creates a new function

B

Defines a constructor for an object

C

Creates a hash

D

Declares a global variable

Q109

Q109 How do you call a method on an object in Perl?

A

$object->method();

B

method($object);

C

$object.method();

D

call method on $object;

Q110

Q110 What does @ISA = ('ParentClass'); do in a Perl package?

A

Defines an object

B

Declares an array

C

Specifies class inheritance

D

Creates a new method

Q111

Q111 Why does calling $object->method(); result in an error?

A

The method does not exist

B

Perl does not support methods

C

The object is not blessed

D

Perl requires an explicit import

Q112

Q112 What is a common mistake when defining a constructor in Perl?

A

Forgetting to bless the object

B

Using new instead of construct

C

Returning a hash instead of a scalar

D

Declaring methods inside the constructor

Q113

Q113 What does the warn function do in Perl?

A

Terminates execution

B

Prints a warning but continues execution

C

Ignores errors

D

Restarts the script

Q114

Q114 How does the eval function help in error handling?

A

Stops execution on an error

B

Executes code and captures errors

C

Logs errors to a file

D

Raises exceptions only for syntax errors

Q115

Q115 What does $@ contain after an eval block?

A

The last evaluated value

B

The last error message

C

The function return value

D

The script's execution time

Q116

Q116 What is the purpose of local $SIG{DIE}?

A

Handles fatal errors

B

Ignores all errors

C

Displays warnings only

D

Restarts the script on failure

Q117

Q117 What will happen when the following Perl code runs?
eval { die "Error occurred"; }; print "After eval";

A

Script terminates

B

Prints "After eval"

C

Throws an error

D

Ignores the die statement

Q118

Q118 What will be the output of eval { 1 / 0 }; print $@;?

A

0

B

Infinity

C

Division by zero error message

D

Syntax error

Q119

Q119 How do you suppress Perl errors without terminating the script?

A

use strict;

B

use eval;

C

eval { };

D

catch { };

Q120

Q120 Why does die "Error" sometimes fail to stop execution?

A

die does not work in Perl

B

The script is inside an eval block

C

Errors require warn

D

Perl does not handle fatal errors

ad verticalad vertical
ad