MCQs on Modules and Libraries | Perl

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)

  1. 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
  2. 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
  3. 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
  4. 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
  5. Which CPAN command updates all installed modules?
    A) cpan update all
    B) cpan upgrade
    C) cpan-outdated | cpanm
    D) cpan refresh
  6. 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
  7. 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
  8. Which command lists all installed CPAN modules?
    A) cpan list
    B) cpanm -l
    C) perldoc perllocal
    D) perl -MCPAN -e
  9. 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
  10. 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)

  1. Which extension is used for Perl modules?
    A) .pl
    B) .pm
    C) .mod
    D) .perl
  2. 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
  3. 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
  4. 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
  5. 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
  6. Which module simplifies module creation and exporting in Perl?
    A) Exporter
    B) Module::Build
    C) ExtUtils::MakeMaker
    D) App::cpanminus
  7. 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;
  8. 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';
  9. Which pragma helps you create object-oriented Perl modules?
    A) base
    B) parent
    C) Both A and B
    D) None
  10. 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)

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. What does use strict do?
    A) Forces declaration of variables
    B) Disables experimental features
    C) Imports CPAN modules
    D) Adds strict typing to variables
  10. Which pragma works with use for warnings?
    A) use warnings;
    B) use caution;
    C) use warn;
    D) use debug;

Answers Table

QNoAnswer (Option with Text)
1A) Comprehensive Perl Archive Network
2A) cpan install Module::Name
3B) To manage and install Perl modules
4D) Both A and C
5C) `cpan-outdated
6D) Both A and C
7B) cpanm Module::Name@Version
8C) perldoc perllocal
9D) All of the above
10D) Run o conf init inside the CPAN shell
11B) .pm
12A) By creating a file and using the package keyword
13A) To signify the module loaded successfully
14A) Using the @EXPORT array in the module
15B) Specifies functions available for optional export
16A) Exporter
17A) use Module::Name;
18A) our $VERSION = '1.0';
19C) Both A and B
20D) Both A and B
21B) Defines the paths Perl searches for modules
22D) Both B and C
23D) All of the above
24A) use loads at compile time, require loads at runtime
25D) Both A and C
26B) Perl throws a compile-time error
27D) Both A and B
28C) Both A and B
29A) Forces declaration of variables
30A) use warnings;

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top