views:

80

answers:

2

I am running Perl script under cygwin which takes input from <STDIN> and process the requests continuously.

#!/usr/bin/perl
print "Enter Input:";
while(<STDIN>) {
    print "Recieved Input: $_";
    print "Enter Input:";
}



    $perl testPerl.pl        
    Enter input:input1
    Recieved input:input1
    Enter input:inpt2
    Recieved input:input2
    Enter input:

Now, I would like the up arrow at the current prompt: "Enter input:" to take the previous inputs i.e "input2","input1"

It behaves as expected when running under windows enivronment (cmd.exe)
But the problem under cygwin is that the up arrow literally takes the cursor 1 row up i.e it takes to the line "Recieved input:input2"

Please share your thoughts on this.

+1  A: 

There's a big difference in the handling of the command line history between the Windows console and Unix terminals. On Windows, it's done by the console, whereas on Unix, applications are responsible for it. I don't know anything about Perl, but you'll need to use something like the readline library. This looks helpful: http://perldoc.perl.org/functions/readline.html

ak
The readline library and the Perl function of the same name are different beasts.
brian d foy
+4  A: 
gorilla