その1:モジュール名のみ
perl -MExtUtils::Installed -le 'print for ExtUtils::Installed->new->modules'
以下とほぼ等価
# !/usr/bin/perl
use strict;
use ExtUtils::Installed; # -MExtUtils::Installed
for (ExtUtils::Installed->new->modules) {
print;
print "\n"; # -l
}
その2:モジュール名とバージョン
perl -MExtUtils::Installed -le 'print "$_\t".eval("use $_(); \$$_\:\:VERSION") for ExtUtils::Installed->new->modules'
以下とほぼ等価
# !/usr/bin/perl
use strict;
use ExtUtils::Installed; # -MExtUtils::Installed
for (ExtUtils::Installed->new->modules) {
print;
print "\t";
print eval "use $_();".'$'.$_.'::VERSION';
print "\n"; # -l
}
その3:モジュール名とバージョンとインストール日時
perldoc -tT perllocal |
perl -nle '$d=$1,$m=$2 if /\s+(.*): "Module" (.*)/;print "$m\t$1\t$d" if /"VERSION: (.*)"/'
perldoc -tT perllocal
を使用。
$ perldoc -tT perllocal
(略)
Sun Sep 1 01:53:32 2019: "Module" ExtUtils::MakeMaker
* "installed into: xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
* "LINKTYPE: dynamic"
* "VERSION: 7.36"
* "EXE_FILES: bin/instmodsh"
(略)
以下とほぼ等価
# !/usr/bin/perl
use strict;
my $cmd = "perldoc -tT perllocal";
open PL, "$cmd |" or die "Can't exec '$cmd': $!";
my ($m,$v,$d);
while(<PL>) {
$d=$1,$m=$2 if /\s+(.*): "Module" (.*)/;
print "$m\t$1\t$d\n" if /"VERSION: (.*)"/;
}