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

Re: better readline?

Thread Previous | Thread Next
Chas. Owens
August 5, 2009 11:03
Re: better readline?
Message ID:
On Tue, Aug 4, 2009 at 16:35, Bryan Harris<> wrote:
>> while ( defined (my $answer = $term->readline("Enter a date and
>> note:", "8/2 Updated database")) ) {
>> print "you said $answer\n";
>> }
> Thanks for the response Chas -- oddly it doesn't work.  This is what it
> prints:
> 2054% ./test
> Enter a date and note:Uh.
> you said Uh.

I assume you changed the second string to "Uh.".  If so, then that is
what is supposed to happen.  $term->readline() prompts with the first
string with a default of the second.  When you hit enter, the input is
stored in $answer.  All my loop does with the answer is tell you what
you said.

> I don't understand the documentation -- I don't know what a "package",
> "stub", or "method" are in this context, and I've been perl coding for
> nearly 10 years!  Obviously experience doesn't always equate to expertise.

Package refers to the multiple readline backends which are implemented
as modules (Term::Readline::GNU, Term::Readline::Perl, etc.).  Some of
these backends have more features than others, but you always have
access to a base level of functionality in Term::Readline::Perl.

Stubs are short functions that don't do anything.  They are needed in
case the backend does not provide a feature.  The stub will be called
instead and do nothing.  This will prevent the program from blowing
up, allowing it to run with reduced functionality.  For instance, a
backend might not provide a history of previous entries.  In that
case, addhistory won't do anything, but calling it won't cause a
runtime error.

A method is a subroutine called on an object:


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