perl脚本来检查是否安装了perl模块

问题描述:

我希望能够在列表中的每个模块上运行此测试.不确定如何使perl遍历每个项目.

I'd like to be able to run this test on each module in the list. Not sure how to ger perl looping over each item.

use Module::Load;
eval {
  load Image::Magick;
  1;
} or die "you need Module to run this program";

  • Bit :: Vector
  • 鲤鱼::氏族
  • 检查::: ISA
  • DBD :: Oracle
  • DBI
  • Data :: GUID
  • Data :: OptList
  • Data :: TreeDumper
  • Data :: UUID
  • Date :: Calc
  • Devel :: Size
  • ExtUtils :: MakeMaker
  • Log :: Dispatch
  • Log :: Dispatch :: File :: Rolling
  • Log :: Dispatch :: FileRotate
  • Log :: Log4perl
  • Params :: Util
  • Params :: Validate
  • 排序::自然地
  • Sub :: Exporter
  • Sub :: Install
  • Sub :: Uplevel
  • Sys :: Syslog
  • Term :: Size
  • Test :: Exception
  • Test :: Simple
  • Test :: use :: ok
  • Tree :: Simple
    • Bit::Vector
    • Carp::Clan
    • Check::ISA
    • DBD::Oracle
    • DBI
    • Data::GUID
    • Data::OptList
    • Data::TreeDumper
    • Data::UUID
    • Date::Calc
    • Devel::Size
    • ExtUtils::MakeMaker
    • Log::Dispatch
    • Log::Dispatch::File::Rolling
    • Log::Dispatch::FileRotate
    • Log::Log4perl
    • Params::Util
    • Params::Validate
    • Sort::Naturally
    • Sub::Exporter
    • Sub::Install
    • Sub::Uplevel
    • Sys::Syslog
    • Term::Size
    • Test::Exception
    • Test::Simple
    • Test::use::ok
    • Tree::Simple

尝试一下:

#!/usr/bin/perl 
use 5.010;
use strict;
use warnings;

my @modules = qw(
    Bit::Vector
    Carp::Clan
    Check::ISA
    DBD::Oracle
    DBI
    Tree::Simple
);

for(@modules) {
    eval "use $_";
    if ($@) {
        warn "Not found : $_" if $@;
    } else {
        say "Found : $_";
    }
}