Perl: List Available Modules, List Module Search Paths

By Xah Lee. Date: . Last updated: .

The standard filename suffix for perl module is “.pm”.

List Available Modules

To get a list of standard module that are bundled with Perl (but not necessarily installed), type in terminal: perldoc perlmodlib.

You can also use the bundled corelist command line util. Use it in terminal.

◆ corelist -a Data::Dumper

Data::Dumper was first released with perl 5.005
  5.005      2.09
…
  v5.13.3    2.126
  v5.13.4    2.126
  v5.13.5    2.128
  v5.13.6    2.129
  v5.13.7    2.130_01
  v5.13.8    2.130_02
  v5.13.9    2.130_02
  v5.13.10   2.130_02
  v5.13.11   2.130_02
  v5.14.0    2.130_02
  v5.14.1    2.130_02
  v5.14.2    2.130_02
◆ corelist  /JSON/

JSON::PP was first released with perl v5.13.9

JSON::PP::Boolean was first released with perl v5.13.9

Load a Module

To load a package, call use module_name;. It will import all functions in that package. Example:

# -*- coding: utf-8 -*-
# perl

# loading some commonly used packages
use Data::Dumper;               # for printing list and hash
use File::Find;                 # for traversing directories

Show Module Documentation

To find out what functions are available in a module, read its documentation, for example perldoc Data::Dumper.

Show Module Load Paths

@INC → predefined variable. A list of library search paths.

Here is a example showing module search paths and loaded modules:

# -*- coding: utf-8 -*-
# perl

use Data::Dumper;

print Dumper \@INC; # prints all module search paths

__END__

$VAR1 = [
          '/etc/perl',
          '/usr/local/lib/perl/5.14.2',
          '/usr/local/share/perl/5.14.2',
          '/usr/lib/perl5',
          '/usr/share/perl5',
          '/usr/lib/perl/5.14',
          '/usr/share/perl/5.14',
          '/usr/local/lib/site_perl',
          '.'
        ];

perldoc perlvar

Show Loaded Modules

%INC → predefined variable. A hash of loaded modules.

# -*- coding: utf-8 -*-
# perl

use Data::Dumper;

print Dumper \%INC; # prints all loaded modules

__END__

$VAR1 = {
          'warnings/register.pm' => '/usr/share/perl/5.14/warnings/register.pm',
          'bytes.pm' => '/usr/share/perl/5.14/bytes.pm',
          'XSLoader.pm' => '/usr/share/perl/5.14/XSLoader.pm',
          'Carp.pm' => '/usr/share/perl/5.14/Carp.pm',
          'Exporter.pm' => '/usr/share/perl/5.14/Exporter.pm',
          'strict.pm' => '/usr/share/perl/5.14/strict.pm',
          'warnings.pm' => '/usr/share/perl/5.14/warnings.pm',
          'overload.pm' => '/usr/share/perl/5.14/overload.pm',
          'Data/Dumper.pm' => '/usr/lib/perl/5.14/Data/Dumper.pm'
        };

perldoc perlvar

If you have a question, put $5 at patreon and message me.

Perl

  1. Perl Overview
  2. Version String
  3. Help System

Detail

  1. Quoting String
  2. Format String
  3. String Operations
  4. True, False
  5. if then else
  6. Loop
  7. List / Array
  8. Loop Thru List
  9. Map f to List
  10. List Comprehension
  11. Hash Table
  12. Function Optional Param
  13. regex
  14. Split Line by Regex

Advanced

  1. Sort List, Matrix, Object
  2. Sort Matrix
  3. List Modules, Search Paths
  4. Write a Module
  5. Read / Write File
  6. Traverse Dir
  7. Find / Replace
  8. Complex Numbers
  9. System Call
  10. Compress / Decompress gzip
  11. Get Env Var
  12. GET Web Content
  13. Unicode 🐪
  14. Convert File Encoding
  15. Sort Unstable