Chinaunix首页 | 论坛 | 博客
  • 博客访问: 49537
  • 博文数量: 51
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 72
  • 用 户 组: 普通用户
  • 注册时间: 2013-04-22 16:36
个人简介

地方

文章分类

全部博文(51)

文章存档

2013年(51)

我的朋友

分类: LINUX

2013-04-22 16:41:39

脚本如下:

#!/usr/bin/perl

use strict;
use warnings;

my @modules = (
    'Data::Dumper',      'POSIX',
    'Cwd',               'threads',
    'threads::shared',   'Thread::Queue',
    'Thread::Semaphore', 'IO::Socket',
    'Proc::Daemon',      'Time::HiRes',
    'DBI',               'DBD::mysql',
    'Algorithm::Diff'
);

foreach my $module (@modules) {
    print "Checking required module '$module'...";
    my $res = \&CheckModule($module);
    if ($res) {
        print "Ok!\n";
        next;
    }

    print "\n------------------------------------------------------------\n";
    print "Required module '$module' is not found on this system!\n";
    print "Install it (run command 'cpan $module') and try again.\n\n";
    exit(1);
}

#-----------------------------------------------------------------
sub CheckModule($) {
    my $module = shift;

    eval "use $module";

    return 1 unless $@;
    print "Error!\n $@";
    return 0;
}

阅读(75) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~