Front page | perl.beginners |
Postings from August 2009
Re: better readline?
Thread Previous
|
Thread Next
From:
Chas. Owens
Date:
August 3, 2009 15:56
Subject:
Re: better readline?
Message ID:
58ce48dc0908031556t3163bc4eod9de456097e2eec9@mail.gmail.com
On Mon, Aug 3, 2009 at 18:43, Bryan R Harris<Bryan_R_Harris@raytheon.com> 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??
>
snip
It sounds like you want [Term::Readline][1]:
#!/usr/bin/perl
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] : http://perldoc.perl.org/Term/ReadLine.html
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
Thread Previous
|
Thread Next