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.
|