Thanks a lot Chas for your your Help. Your code is running excellently.Now I
have some doubts and questions to you.

1) if (eval "use $module; 1") -- from this line I understand that u are
taking the exit status of the use command and if it is true then the module
is installed. But where you are storing the exit status of the use command.

What this line is actually does Can you please describe me in detail--
print "$module is version ", eval '$' . $module . "::VERSION", "\n";

I am storing the version number of the module in a variable by using
$version=eval '$' . $module . "::VERSION";( it is working properly)
but I can't understand How this thing are working.

2) Suppose I want to check that perl ( or some other application) is
installed in the system or not. Can this be done using Eval?    I have tried
with a small code but if the application is installed it is working properly
but If the Application is not installed Then it is not working.

if( eval "`which perl`; 1")
{
        print "Perl Is installed in system\n";
}
else
{ not installed."\n";}

it is working properly
but when I am changing the name from perl to abc( which doesn't exists) then
it is also getting entered into if block;

I have also tried with the following code but here also it prints the if
block print message.
if( eval "`which abc 2>>/dev/null`; 1")
{
        print "ABC Is installed in system\n";
}
elsif(eval "`which abc 2>>/dev/null`;0")
{ print "No perl Installed\n";}

Thanks & Regards in Advance
Anirban Adhikary.




On Wed, Nov 5, 2008 at 9:22 PM, Chas. Owens <[EMAIL PROTECTED]> wrote:

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

Reply via email to