On Wed, Nov 5, 2008 at 01:03, Anirban Adhikary
<[EMAIL PROTECTED]> wrote:
> Dear List
> I am trying to check some modules are installed or not in the system and if
> modules are installed then trying to check their version number is according
> to our requirement or not.
>
> use strict;
> use warning;
> my @mod_info=("DBD::Oracle","abc","DBI","Parallel::ForkManager",);
> my $module;
> my $version;
> my $install_module;
>
> foreach $module(@mod_info)
> {
>        chomp($module);
>         eval{$install_module = `$perl_path -e 'use $module'
> 2>>/dev/null`};
>        if(defined $install_module)
>        {
>          print "$module is not installed in your system\n";
>        }
>        $version = `$perl_path  -M$module -e 'print "\$\$module::VERSION"'`;
>        print $version."\n";
> }
>
> As there is no module by name abc the -- Can't locate abc.pm in @INC error
> message is coming on the screen but when I am running this one liner from
> command line I am not getting any error message on screen. Actually I want
> to hold the return status in a variable then trying to do further work. How
> this is possible? In the case of version checking I am not getting  any o/p
> on screen .
>
> One more thing I am aware of using * ExtUtils::Installed* in this scenario
> but I don't want to use any module.
>
> Thanks & Regards in advance
> Anirban Adhikary
>

This is one of the few cases were string eval is not evil:

#!/usr/bin/perl

use strict;
use warnings;

my @list_of_modules =qw/abc.pm List::Util/;

for my $module (@list_of_modules) {
    if (eval "use $module; 1") {
        print "$module is version ", eval '$' . $module . "::VERSION", "\n";
    } else {
        print "$module is not installed\n";
    }
}




-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to