Here is a small program that "requires" a list of modules and prints their versions. It only works for modules that have $VERSION defined:
#!/usr/bin/perl -w
use strict;
my @modules = qw(
File::Copy
File::Find
File::Foo
File::Spec
File::Temp
);
for my $module (@modules) {
my $version;
eval "require $module";
if (not $@) {
$version = $module->VERSION;
$version = '(unknown)' if not defined $version;
}
else {
$version = '(not installed)';
}
print $module, "\t", $version, "\n";
}
__END__
Prints:
File::Copy 2.03
File::Find (unknown)
File::Foo (not installed)
File::Spec 0.82
File::Temp 0.12
In your example you should check the $@ variable, see perlvar, after using eval to see if there was as error:
print "Eval error: ", $@ if $@;
--
John.
|