Category: Basic Keywords: Module
qw的解释
use Module qw(argu param);中qw的解释qw中的内容在本语句执行后,便成为Module里的import函数的参数。例解如下:
#TEst.pm
package TEst;
sub import {
print "@_";
}
1;
#test.pl
#!/usr/bin/perl
use TEst qw(argu param);
__OUTPUT__
TEst argu param
参考:Randal L. Schwartz's Hey, 'use' guys! Import this!
查找已安装模块
use ExtUtils::Installed; my $inst = ExtUtils::Installed->new(); print join "\n", $inst->modules();
检查批量模块是否已安装
#!/usr/bin/perl
# Check the needed modules are installed in currect system
print "Content-Type: text/html\r\n\r\n";
while (<DATA>) {
s/[^\w\:]*//g;
next unless ($_);
eval("use $_;");
if ($@) {
print "<font color=red>$_</font> failed to locate.<br>";
} else {
print "<font color=blue>$_</font> locate success!<br>";
}
}
# add the module name you want to check
__DATA__
strict
CGI::Carp
CGI
Net::SMTP
TEM_P