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

  • Home
  • SEARCH
  • 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 4621048
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:38:41+00:00 2026-05-22T02:38:41+00:00

I’m writing a program for others to use. One of the design specs is

  • 0

I’m writing a program for others to use. One of the design specs is to use the Term::ReadLine::Gnu Perl library. Most of the users will not have this installed and I want to install it while the program is running.

So, when the user starts the program they do not have the library installed. My program will install it for them while they are using the program using the OS package manager.

This is how I’m checking for the module

         require Term::ReadLine;

         my $Readline_Support = 1;
         eval { require Term::ReadLine::Gnu }
           or $Readline_Support = 0;

I use the $Readline_Support variable to redirect the terminal, use the history file etc.

          $OUT = $TERMINAL->OUT if $readline_installed;
          if ($readline_installed)
          {
            # save every answer and default, good or not, to the history file
            $TERMINAL->add_history($Ans);
            $TERMINAL->append_history(1, HIST_FILE);
          }

Unfortunately, I get this error when I try to use the history file:

Can’t locate object method “using_history” via package “Term::ReadLine::Stub” at ./msi.pl line 618, line 2.

line 618 is

          $TERMINAL->using_history();

Which is the first use of the $TERMINAL object.

Has any one had experience with installing Perl modules while the script is running and then using the modules in that same script?

Ok… Thanks to Andy if the module is not installed this works

          # I removed the  require Term::ReadLine; here
          my $Readline_Support = 1;
          eval { require Term::ReadLine::Gnu }
            or $Readline_Support = 0;

below in the code

            if ($readline_installed)
            {
              # Required for the dynamic loading of Term::ReadLine::Gnu
              require Term::ReadLine;

              $TERMINAL = Term::ReadLine->new ('ProgramName')
                 if $Interactive or $Brief
            }

Now, however, the check for the installed mod always fails, I think because

            require Term::ReadLine::Gnu;

needs

            require Term::ReadLine;

early in the code, like the old

     require Term::ReadLine;

     my $Readline_Support = 1;
     eval { require Term::ReadLine::Gnu }
       or $Readline_Support = 0;
  • 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-05-22T02:38:41+00:00Added an answer on May 22, 2026 at 2:38 am

    I see in the code for Term::ReadLine that it determines which implementation it is going to use at load time, as opposed to when new is called. So I would suggest the following sequence:

    1. test for availability of Term::ReadLine::Gnu just like you are currently, but before loading any ReadLine modules
    2. install Term::ReadLine::Gnu if not present
    3. require Term::ReadLine
    4. create your object with Term::ReadLine->new

    Things are made more complicated because Term::ReadLine::Gnu throws an error on an attempt to load it directly with use or require, so the straightforward eval test fails even when it’s installed. One way to deal with that is to parse $@, but I don’t like parsing diagnostic messages because there’s a risk they may change over time. Deleting from %INC doesn’t seem great either, but should work as long as the error on a direct load of Term::ReadLine::Gnu doesn’t go away.

    my $readline_installed = 1;
    unless (eval { require Term::ReadLine::Gnu; }) {
        # Term::ReadLine::Gnu throws an error that it can't be loaded directly,
        # even when it's installed.
        $readline_installed = exists ($INC{"Term/ReadLine/Gnu.pm"});
    
        # Needed so that it will be reloaded after installation
        delete $INC{"Term/ReadLine/Gnu.pm"};
    }
    
    unless ($readline_installed) {
        print "Installing Term::ReadLine::Gnu\n";
        # ...
    }
    
    require Term::ReadLine;
    
    my $term = Term::ReadLine->new ("app");
    $term->addhistory ("blah");
    print $term->readline ("> "), "\n";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am confused How to use looping for Json response Array in another Array.
I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am writing an app with both english and french support. The app requests
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm making a simple page using Google Maps API 3. My first. One marker
Let's say I'm outputting a post title and in our database, it's Hello Y’all

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.