Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7754749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:23:26+00:00 2026-06-01T12:23:26+00:00

Based on the solution provided in Test for existence of perl mod inside script

  • 0

Based on the solution provided in Test for existence of perl mod inside script, I came up with the following test:

my @mods = (qw(Cwd DBI Date::Calc Term::ReadLine File::Copy Digest::Perl::MD5
               LWP::Simple Switch POSIX Text::LevenshteinXS File::Spec
               File::Basename String::CRC32 MIME::Lite IO::Socket::INET));

foreach my $mod (@mods) {
    ( my $fn = "$mod.pm" ) =~ s|::|/|g;    # Foo::Bar::Baz => Foo/Bar/Baz.pm
    if ( eval { require $fn; 1; } ) {
        print "Module $mod loaded ok\n";
    } else {
        print "Could not load $mod. Error Message: $@\n";
    }
}

When I originally just had use something, I also sometimes had imports, which I now find will not work with require, i.e.:

use Digest::Perl::MD5 'md5_hex';

After the @mods test, I would like to load them, so:

require Cwd;
require DBI;
require Date::Calc;
require Term::ReadLine;
require File::Copy;
require Digest::Perl::MD5 'md5_hex';
require LWP::Simple;
require Switch;
require POSIX;
require Text::LevenshteinXS qw(distance);
require File::Spec;
require File::Basename;
require String::CRC32;
require MIME::Lite;
require IO::Socket::INET;

But this throws an error on run:

syntax error at ./mod.pl line 78, near "require Digest::Perl::MD5 'md5_hex'"
syntax error at ./mod.pl line 82, near "require Text::LevenshteinXS qw(distance)"

How can I do this?

EDIT:
For anyone else who stumbles upon this thread later on, here’s the working code:

use strict;

$| = 1;

################################################
# Help user if Perl mods are missing
################################################
my @mods = (qw(DBI Date::Calc Term::ReadLine File::Copy Digest::MD5 LWP::Simple Text::LevenshteinXS File::Spec String::CRC32 MIME::Lite IO::Socket::INET Getopt::Long));

foreach my $mod (@mods) {
    ( my $fn = "$mod.pm" ) =~ s|::|/|g;    # Foo::Bar::Baz => Foo/Bar/Baz.pm
    if ( eval { require $fn; 1; } ) {
        ##print "Module $mod loaded ok\n";
    } else {
        print "You are missing a required Perl Module: $mod\n";
        my $ok = &getYN( "Shall I attempt to install it for you?", "y" );
        if ( $ok =~ /[Yy]/ ) {
            require CPAN;
            CPAN::install($mod);
        } else {
            print "LogZilla requires $mod\n";
            exit;
        }
    }
}

use feature "switch";
use Cwd;
use File::Basename;
use POSIX;
require DBI;
require Date::Calc;
require Term::ReadLine;
require File::Copy;
require Digest::MD5->import("md5_hex");
require LWP::Simple;
require Text::LevenshteinXS->import("distance");
require File::Spec;
require String::CRC32;
require MIME::Lite;
require IO::Socket::INET;
require Getopt::Long;

my ($autoyes);

sub getYN {
    unless ( $autoyes =~ /[Yy]/ ) {
        my ( $prompt, $default ) = @_;
        my $defaultValue = $default ? "[$default]" : "";
        print "$prompt $defaultValue: ";
        chomp( my $input = <STDIN> );
        return $input ? $input : $default;
    } else {
        return "Y";
    }
}

sub prompt {
    my ( $prompt, $default ) = @_;
    my $defaultValue = $default ? "[$default]" : "";
    print "$prompt $defaultValue: ";
    chomp( my $input = <STDIN> );
    return $input ? $input : $default;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:23:28+00:00Added an answer on June 1, 2026 at 12:23 pm

    You need to call the modules’ import method, e.g.

    Digest::Perl::MD5->import("md5_hex");
    Text::LevenshteinXS->import("distance");
    

    use Module is exactly equivalent to

     BEGIN { require Module; Module::->import( LIST ); }
    
    • require
    • use
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following simple script to test the mkdir() function in PHP: <?php
(A working solution, based on the responses, is provided at the end of this
Has anyone successfully implemented a Java based solution that uses Microsoft SQL Server 2005
We are building a web based solution right now and it is almost ready
I have a solution based on ASP, VB6, COM and SQL Server. The web
I'm involved in creating a web based business solution. The idea is that the
I am looking for a good role based authorization solution to use alongside Authlogic.
I work at a college that uses an intranet based student management solution not
I would like to enable/disable some code based on a custom solution configuration I
I'm looking for a good solution for graphically viewing a SOAP-based web service and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.