Sorry, but you are being fooled by the cmd.exe shell's history facility, into believing that Term::ReadLine is doing something. It isn't.

The following is a completely new command shell where I type 'perl', hit enter, and then paste your snippet. When I get to your prompt I hit the up-arrow key twice. See what is displayed?

Microsoft Windows [Version 6.0.6001] Copyright (c) 2006 Microsoft Corporation. All rights reserved. c:\>perl use Term::ReadLine; my $cli = Term::ReadLine->new; if ($^O eq "MSWin32" || $^O eq "dos") { my $INPUT; open($INPUT, "<con") and $cli->newTTY($INPUT, $cli->OUT); } my $line1 = $cli->readline; my $line2 = $cli->readline; # hit up arrow for line1 history use Data::Dumper; print Dumper $line1, $line2; ^Z INPUT> print Dumper $line1, $line2;

Uparrow twice recalls the 2nd to last line (the last '^z' is displayed on the first uparrow), of input to the command shell. Term::ReadLine cannot possibly be caching this line as it hasn't started running when that is entered.

You can get exactly the same recall without using Term::ReadLien at all. This is another new shell window--note the =comment/=cut lines:

Microsoft Windows [Version 6.0.6001] Copyright (c) 2006 Microsoft Corporation. All rights reserved. c:\>perl =comment use Term::ReadLine; my $cli = Term::ReadLine->new; if ($^O eq "MSWin32" || $^O eq "dos") { my $INPUT; open($INPUT, "<con") and $cli->newTTY($INPUT, $cli->OUT); } my $line1 = $cli->readline; my $line2 = $cli->readline; # hit up arrow for line1 history use Data::Dumper; print Dumper $line1, $line2; =cut printf "PROMPT> "; <STDIN>; ^Z PROMPT> my $line2 = $cli->readline; # hit up arrow for line1 history

Even though the executable part of the program consists of just printf "PROMPT> "; <STDIN>;, I can cycle back and forth through the entire text entered in this shell session.

The first problem with Term::ReadLine (on windows) is that it doesn't use the arrow keys. You have to use some arcane ctrl-alt-meta-key combination to activate it. The second is that is does provide half the functionality of the shell facility.

That's one of the reasons I disable readline support in cpan. It's disrespect for my current/preferred console settings is another


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy

In reply to Re^3: Simulating Command Line History in Perl by BrowserUk
in thread Simulating Command Line History in Perl by Only1KW

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.