Journal(2005) | Blog(2006) | RandomLink | WhoAmI | LiveBookmark | HomePage

<<Previous: PerlTidy  >>Next: 如何将Perl代码着色

Module

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

<<Previous: PerlTidy  >>Next: 如何将Perl代码着色

Options: +Del.icio.us

Related items Created on 2004-10-30 19:10:08, Last modified on 2005-05-21 00:16:04
Copyright 2004-2005 All Rights Reserved. Powered by Eplanet && Catalyst 5.62.