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