Re: Can't get desired o/p with this code
- From: chas.owens@xxxxxxxxx (Chas. Owens)
- Date: Wed, 5 Nov 2008 10:52:40 -0500
On Wed, Nov 5, 2008 at 01:03, Anirban Adhikary
<anirban.adhikary@xxxxxxxxx> 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.
.
- Follow-Ups:
- Re: Can't get desired o/p with this code
- From: Anirban Adhikary
- Re: Can't get desired o/p with this code
- References:
- Can't get desired o/p with this code
- From: "Anirban Adhikary"
- Can't get desired o/p with this code
- Prev by Date: Re: merge 2 or more files together without creating new file
- Next by Date: Re: merge 2 or more files together without creating new file
- Previous by thread: Can't get desired o/p with this code
- Next by thread: Re: Can't get desired o/p with this code
- Index(es):
Relevant Pages
|