perl script to check if perl modules are installed

前端 未结 4 1378
无人共我
无人共我 2021-01-20 19:27

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::Mag         


        
4条回答
  •  北海茫月
    2021-01-20 20:15

    If you don't need to use Perl to do this, you could do this in a shell script:

    #!/bin/sh
    MODULES="Data::Dumper Foobar::Test"
    
    for i in $MODULES ; do
      if $(perl -M$i -e '1;' >/dev/null 2>&1 ); do
        echo "Ok."
      else
        echo "No." 
      fi
    done
    

    You could do something else other than using echo.

    The code sequence:

    perl -MData::Dumper '1;'
    

    will exit with an error value of 0 (ok) and

    perl -MFoobar::Test '1;'
    

    will exit with an error value of 2 (error occurred).

提交回复
热议问题