以下のようなテストスクリプトを用意する。
#!/usr/bin/perl -w use strict; use warnings; exit; __END__
最も簡単な方法はデバッガを使うこと。以下のようにperlの起動引数に-dを加え、起動したらMでモジュールの種類とパスとバージョンがわかる。ただし、デバッガの起動に必要なモジュールも表示される。
$ perl -d module.pl Loading DB routines from perl5db.pl version 1.32 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(test.pl:4): exit; main::(test.pl:5): __END__ DB<1> M 'Carp.pm' => '1.25 from /usr/local/share/perl/5.10.1/Carp.pm' 'Config.pm' => '/usr/lib/perl/5.10/Config.pm' 'Config_git.pl' => '/usr/lib/perl/5.10/Config_git.pl' 'Config_heavy.pl' => '/usr/lib/perl/5.10/Config_heavy.pl' 'Exporter.pm' => '5.66 from /usr/local/share/perl/5.10.1/Exporter.pm' 'IO.pm' => '1.25 from /usr/lib/perl/5.10/IO.pm' 'IO/Handle.pm' => '1.28 from /usr/lib/perl/5.10/IO/Handle.pm' 'SelectSaver.pm' => '1.02 from /usr/share/perl/5.10/SelectSaver.pm' 'Symbol.pm' => '1.07 from /usr/share/perl/5.10/Symbol.pm' 'Term/Cap.pm' => '1.12 from /usr/share/perl/5.10/Term/Cap.pm' 'Term/ReadLine.pm' => '1.09 from /usr/local/share/perl/5.10.1/Term/ReadLine.pm' 'XSLoader.pm' => '0.15 from /usr/local/lib/perl/5.10.1/XSLoader.pm' 'perl5db.pl' => '1.32 from /usr/share/perl/5.10/perl5db.pl' 'strict.pm' => '1.04 from /usr/share/perl/5.10/strict.pm' 'vars.pm' => '1.01 from /usr/share/perl/5.10/vars.pm' 'warnings.pm' => '1.06 from /usr/share/perl/5.10/warnings.pm' 'warnings/register.pm' => '1.01 from /usr/share/perl/5.10/warnings/register.pm' DB<1> q
デバッガが使えない場合は以下のようなサブルーチンを使う。
#!/usr/bin/perl -w use strict; use warnings; module(); exit; sub module { foreach ( sort keys %INC ) { my $module = $_; $module =~ s/.pm$//; $module =~ s#/#::#g; my $var = $module->VERSION; if ( defined $var ) { print "$var\t"; } else { print "\t"; } print "$module\t$INC{$_}\n"; } }
この場合は以下のようになる。
$ perl module.pl 1.04 strict /usr/share/perl/5.10/strict.pm 1.06 warnings /usr/share/perl/5.10/warnings.pm