Discipulus I'm very glad you managed it on your own, seriously! :)

Term::ReadLine is indeed very confusing and it took me many attempts to understand the debugger and long studies of the documentation of gnu-readline (i.e. the original c-library) including sample scripts in Term::ReadLine::Gnu to get used to it.

IMHO gnu-readline predates T'RL and it was originally only thought as a wrapper with a thin Stub as fall back. People were meant to know gnu-readline and to understand the limitations.

> and a strange behaviour (still obscure to me)

as I told you it's using Autoloading, i.e. the function is installed after first use, such that exists fails before that.

>  continue{ &define_completion_func($hr);}

this really confused me, till I understood that you want to set up a new set of commands in the $hr hashref.

But since its a closed over variable in the completion-function you might also simply reset it with something like %$hr=%CMD .

PLEASE NOTE that your code should now work with most Term::ReadLine::* sub-packages (except ::Stub of course)

The following code is a proof of concept I wrote yesterday, you can pass the name of the implementation module to test it or hardcode the module to test by default.

#!/usr/bin/perl use strict; use warnings; my $module; BEGIN { my $opt = $ARGV[0]; $ENV{PERL_RL} = $opt || qw(Gnu Perl Zoid)[0]; # choose module $module = $ENV{PERL_RL}; } use Term::ReadLine; my $term = Term::ReadLine->new('sample'); my $attribs = $term->Attribs; completion_words('print', 'list', 'quit', 'run', 'status'); $term->readline("$module> "); sub completion_words { my @basic_commands = @_; my $c_completion = sub { my ($text, $line, $start) = @_; #return () if $start != 0; # only at start grep(/^$text/, @basic_commands); }; $attribs->{completion_function} = $c_completion; }

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)


In reply to Re^4: about Term::ReadLine and it's imported function The Solution by LanX
in thread about Term::ReadLine and it's imported function by Discipulus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.