How to check wether a module is installed in Perl?

There are many scenarios  that we are in need to check the availability of a module both programatically and via the Terminal.

If we need to check it via Terminal or command prompt, use the following method :

perl -XML::RSSGEN -e 1

If you need to check it via the Perl program use the below script to get the result.

sub try_load {
  my $mod = shift;

  eval("use $mod");

  if ($@) {
    return(0);
  } else {
    return(1);
  }
}
my $module = "XML::RSSGEN";
if (try_load($module)) {
  print "loaded\n";
} else {
  print "not loaded\n";
}