develooper Front page | perl.beginners | Postings from August 2009

Re: better readline?

Thread Previous | Thread Next
Chas. Owens
August 3, 2009 15:56
Re: better readline?
Message ID:
On Mon, Aug 3, 2009 at 18:43, Bryan R Harris<> wrote:
> I'm writing a little script where the user enters some data via keyboard.
> The script in some cases can guess what the user will want to enter, but I'd
> like the user to be able to override what the computer has guessed.
> For example, the computer thinks the user will enter "8/2 Updated database",
> but the user may want to enter "8/2 Removed links table".
> Is there a way to have perl prompt the user thusly:
>  Enter a date and note:  8/2 Updated database<cursor goes here>
> ... but then the user could backspace all the way back to 8/2 and change it
> if they want?  Almost like I'm pushing something into <STDIN>, which will
> then get read back out?
> I'm not even sure what words to use to ask, but I hope that's clear enough??

It sounds like you want [Term::Readline][1]:


use strict;
use warnings;

use Term::Readline;

my $term = Term::ReadLine->new("progname");

while ( defined (my $answer = $term->readline("Enter a date and
note:", "8/2 Updated database")) ) {
	print "you said $answer\n";

[1] :

Chas. Owens
The most important skill a programmer can have is the ability to read.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About