oko1 has asked for the wisdom of the Perl Monks concerning the following question:

Greetings, O Monks -

I've used Term::Readline on and off over a period of years, but have now run up against a limitation (whether it's in my own knowledge or in the module remains to be seen. :) So far, I've spent a couple of hours banging away at this problem and getting nowhere, and have run several SuperSearches here with no result - so I figure it's time to appeal to the collective but not-yet-recorded wisdom of the Monastery. Incidentally, I'm using the Term::ReadLine::Gnu extension, which is supposed to make the original Term::ReadLine much smarter. As far as I can tell, its IQ has remained the same.

What I'd like is to have is two prompts within my script, each of which keeps its own history. Any suggestions?


-- 
Human history becomes more and more a race between education and catastrophe. -- HG Wells
  • Comment on Term::Readline - are multiple histories possible?

Replies are listed 'Best First'.
Re: Term::Readline - are multiple histories possible?
by pc88mxer (Vicar) on Apr 07, 2008 at 16:41 UTC
    My experiment with trying to instantiate two Term::ReadLine objects didn't work.

    However, GNU ReadLine has the SetHistory function which is also documented in the perl module, so you could just set the history to whatever you want before calling readline. Instead of calling addhistory, just maintain the history for each prompt in a separate array.

      Yeah, that's one of the first things I tried myself - in several different ways. Didn't work out for me either.

      As to SetHistory, the docs say

        "SetHistory(LINE1 [, LINE2, ...])"
        sets the history of input, from where it can be used if the actual "readline" is present.
      

      That implies, to me, that the lines get saved to a "history" (however that's implemented internally) rather than allowing the option of saving to an array. I suppose I could 1) read each line as it comes in, 2) save it to the appropriate array, 3) clear the history (at each prompt) and load it from the array... but that seems like I'd be reimplementing 90% of the module just to get that extra bit of functionality.

      I'm guessing that it's possible to do this; I was just hoping that someone here would have actual experience with this aspect of the module. I'll keep grinding away at it, though, and report the results if no one else has a definite answer.

      
      -- 
      Human history becomes more and more a race between education and catastrophe. -- HG Wells