paperlined.org
dev > perl > debug_tips
document updated 3 days ago, on Jul 29, 2025

list all modules that get loaded at runtime

A great module for this is Devel::DumpTrace.

As a script is quitting, record a list of all modules that got loaded

An alternative to Devel::DumpTrace:

Step 1) Add this code anywhere in your main Perl script:

END {
    # Whenever this script shuts down, record a list of all Perl code files that
    # were used while it was running.
    use Cwd 'abs_path';
    my $logfile = abs_path($0);
    $logfile =~ s#/#_#g;
    $logfile = "/tmp/Perl_files$logfile." . getpwuid( $< ) . ".txt";
    if (open my $f, '>', $logfile) {
        print $f join("\n", sort values %INC, abs_path($0)), "\n";
        print "Perl file list output to file $logfile\n"   if (-t STDOUT);
    }
}

Step 2) Run your script, and afterwards there should be a file generated named something like /tmp/Perl_files...$USER.txt.

Step 3) If you want to search for a subroutine or variable within that list of files:

$ grep 'regex' $(cat /tmp/Perl_files_blahblah.root.txt)

This works for CGI scripts too, though in that case, you might have to try to guess the name of the file that was written: ls -lrt /tmp/Perl_files_*

TODO: It's known that this Perl code breaks when running under Perl's taint mode (such as when the script has been sudo'd). Fix this at some point.