Master the essential aspects of Perl modules and libraries with these MCQs. Learn about CPAN modules, custom modules, and crucial concepts like @INC, use, and require for efficient coding.
Installing and Using CPAN Modules (10 Questions)
What does CPAN stand for? A) Comprehensive Perl Archive Network B) Complete Perl Archive Node C) Comprehensive Programming Archive Network D) Central Perl Application Network
Which command is used to install a module from CPAN? A) cpan install Module::Name B) perl install Module::Name C) install module Module::Name D) use CPAN Module::Name
What is the purpose of the CPAN module? A) To run Perl scripts B) To manage and install Perl modules C) To test Perl scripts D) To list installed modules
How can you check if a CPAN module is installed? A) Using the perl -MModule::Name -e1 command B) Using the cpan -check Module::Name command C) Running require Module::Name in a script D) Both A and C
Which CPAN command updates all installed modules? A) cpan update all B) cpan upgrade C) cpan-outdated | cpanm D) cpan refresh
What is the purpose of the cpanminus (cpanm) tool? A) Simplifies module installation from CPAN B) Removes unused modules C) Manages module dependencies D) Both A and C
How do you install a specific version of a CPAN module? A) cpan Module::Name=Version B) cpanm Module::Name@Version C) cpan Module::Name.Version D) perl -M Module::Name -Version
Which command lists all installed CPAN modules? A) cpan list B) cpanm -l C) perldoc perllocal D) perl -MCPAN -e
Where are the CPAN modules typically installed on a system? A) /usr/local/lib/perl5 B) /usr/lib/perl5 C) $PERL5LIB D) All of the above
How do you update the CPAN configuration? A) Run cpan configure B) Edit the Config.pm file C) Use cpan -r D) Run o conf init inside the CPAN shell
Creating and Using Custom Modules (10 Questions)
Which extension is used for Perl modules? A) .pl B) .pm C) .mod D) .perl
How do you define a module in Perl? A) By creating a file and using the package keyword B) By writing a script starting with module C) Using the use module statement D) Importing from CPAN
What is the purpose of the 1; statement at the end of a module? A) To signify the module loaded successfully B) To terminate the module C) To include external modules D) To specify the module version
How do you export functions from a custom module? A) Using the @EXPORT array in the module B) Using the require keyword C) Using the sub EXPORT function D) Using the @EXPORT_OK array
What does the @EXPORT_OK array do? A) Automatically exports all functions B) Specifies functions available for optional export C) Prevents any function from being exported D) Specifies mandatory exports
Which module simplifies module creation and exporting in Perl? A) Exporter B) Module::Build C) ExtUtils::MakeMaker D) App::cpanminus
How do you use a custom module in a script? A) use Module::Name; B) import Module::Name; C) call Module::Name; D) include Module::Name;
What is the correct syntax for specifying a version in a module? A) our $VERSION = '1.0'; B) module_version = 1.0; C) use Version => '1.0'; D) set VERSION '1.0';
Which pragma helps you create object-oriented Perl modules? A) base B) parent C) Both A and B D) None
How do you write a test script for a custom module? A) Use Test::More and call functions within the test file B) Create a .t file and run perl test C) Create a test section in the module file D) Both A and B
Understanding @INC and use/require (10 Questions)
What is the purpose of @INC in Perl? A) Stores all loaded modules B) Defines the paths Perl searches for modules C) Manages environment variables for Perl D) None of the above
How do you view the contents of @INC? A) print @INC; B) perl -V C) use Data::Dumper; print Dumper(\@INC); D) Both B and C
How can you add a custom path to @INC? A) use lib '/path/to/modules'; B) push @INC, '/path/to/modules'; C) Set the PERL5LIB environment variable D) All of the above
What is the difference between use and require? A) use loads at compile time, require loads at runtime B) require imports functions, use does not C) require is faster than use D) There is no difference
When is require typically used? A) For conditional module loading B) To import specific functions C) To load modules at runtime D) Both A and C
What happens if a module is not found in @INC? A) The script continues without loading the module B) Perl throws a compile-time error C) Perl searches the web for the module D) Perl skips to the next module
How do you ensure a specific version of a module is used? A) use Module::Name Version; B) use Module::Name '>=Version'; C) require Module::Name >=Version; D) Both A and B
How do you check if a module loaded successfully using require? A) Using an eval block B) Checking the return value of require C) Both A and B D) It cannot be checked
What does use strict do? A) Forces declaration of variables B) Disables experimental features C) Imports CPAN modules D) Adds strict typing to variables
Which pragma works with use for warnings? A) use warnings; B) use caution; C) use warn; D) use debug;
Answers Table
QNo
Answer (Option with Text)
1
A) Comprehensive Perl Archive Network
2
A) cpan install Module::Name
3
B) To manage and install Perl modules
4
D) Both A and C
5
C) `cpan-outdated
6
D) Both A and C
7
B) cpanm Module::Name@Version
8
C) perldoc perllocal
9
D) All of the above
10
D) Run o conf init inside the CPAN shell
11
B) .pm
12
A) By creating a file and using the package keyword
13
A) To signify the module loaded successfully
14
A) Using the @EXPORT array in the module
15
B) Specifies functions available for optional export
16
A) Exporter
17
A) use Module::Name;
18
A) our $VERSION = '1.0';
19
C) Both A and B
20
D) Both A and B
21
B) Defines the paths Perl searches for modules
22
D) Both B and C
23
D) All of the above
24
A) use loads at compile time, require loads at runtime