Which modules are currently loaded by process?

Have you ever wondered which modules are currently loaded by current process? With Perl it's very simple to know this piece of info. Perl saves loaded modules in a hash %INC.

Lets have some dirty hands:

use Data::Dumper;
print STDERR Dumper \%INC;

The output is as follows:

$VAR1 = {
          'warnings/register.pm' => '/usr/share/perl5/warnings/register.pm',
          'bytes.pm' => '/usr/share/perl5/bytes.pm',
          'XSLoader.pm' => '/usr/lib64/perl5/XSLoader.pm',
          'Carp.pm' => '/usr/share/perl5/Carp.pm',
          'Exporter.pm' => '/usr/share/perl5/Exporter.pm',
          'warnings.pm' => '/usr/share/perl5/warnings.pm',
          'overload.pm' => '/usr/share/perl5/overload.pm',
          'Data/Dumper.pm' => '/usr/lib64/perl5/Data/Dumper.pm'
        };

The hash simply contains the module path as value.

So this can be used for cleaning up too, with it you can figure out why you're not getting the version of the module you're expecting, for example.


4 Comments

I like Devel::TraceUse. I've used it a lot developing Type::Tiny to help me figure out where I'm unnecessarily loading modules.

However, unless I've missed a feature it does not tell you the full path of each module that has been loaded like Dumper \%INC does.

Perhaps a pull request is in order :)

Another alternative is Devel::EndStats::LoadedMods which, instead of showing by load order, simply prints list of loaded modules at the end of program run.

Leave a comment

About Ashraf Bashir

user-pic Perling, Perling .... and Perling!