Re: Can't get desired o/p with this code



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.
.



Relevant Pages

  • RE: using strict
    ... RESPONSE FROM DEREK: I did notice this after you pointed it out, ... the error message should point you to the line where ... There is no declaration of the $line variable. ... so use strict disallows them knowing that if you really ...
    (perl.beginners)
  • Re: out of memory problem
    ... use strict; ... variable in the error message so you know *why* it ... foreach my $dir { ...
    (perl.beginners)
  • Re: SP2 Wont Install
    ... in the partial log posted here neither FATAL or WARNING appear. ... 0xf00d from the log to an 0x80242008 error code. ... On the Edit menu, click Find, and then search for the specific error message. ... Additionally, if you do not know which error occurred on the Windows update Web site or you want to find more information about a failure by Automatic Updates, search for the following key words: ...
    (microsoft.public.windowsupdate)
  • Re: Zero values cause errors on log scale
    ... >and the warning is telling you something important. ... The Excel error message is infuriating because it cannot be disabled on ... a per plot basis. ... precisely zero values. ...
    (microsoft.public.excel.charting)
  • Event Viewer Error Messages
    ... I am frequently getting an error message in the "System" Event Log. ... At the exact same time a warning message is being logged. ... events are then logged-in once again 15 seconds later. ... no user action is required." ...
    (microsoft.public.windowsxp.hardware)