I'm so frustrated with the Term::ReadLine::Gnu module: I don't know whether it's the Perl implementation or the underlying readline library functionality but it's making me crazy.

What I need is to have a standard readline-enabled script, BUT I must be able to remove some entries from the history. For example if someone enters a command with a password I need to be able to take that out and rewrite it with a version that hides the password, so the password is not left in the history file.

I'm absolutely bonkers trying to get this to work. Ideally there would be a way to have readline() simply not add anything to the history, and then I'd call addhistory() myself when I wanted. However that doesn't appear to be possible.

So then I tried to use remove_history(where_history()) to remove the last entry from the history. But first, the history position is not set when you invoke ReadHistory(); it's left at 0; readline() will set it but I don't always invoke readline() (sometimes the commands are given non-interactively, on the command line, but I still want them in the history). So I had to call history_set_pos(scalar(GetHistory())) to force it to be set to the end of the history.

But even then, remove_history(where_history()) doesn't work; the entry still appears in the history and the next readline() will move you past it again.

Please, great Monks! Can you tell me how to disable automatic history adding in Term::ReadLine::Gnu, or if not, give me some hints as to how to manipulate the history in a reliable way! My history can be very large (1000 entries) and so completely recreating it at every prompt is not something I'm too excited about :-/


In reply to Term::ReadLine::Gnu vs. history control by madscientist

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.