Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Trying out the example from Term::ReadLine's Synopsis:

use Term::ReadLine;
my $term = Term::ReadLine->new('Simple Perl calc');
my $prompt = "Enter your arithmetic expression: ";
my $OUT = $term->OUT || \*STDOUT;
while ( defined ($_ = $term->readline($prompt)) ) {
    my $res = eval($_);
    warn $@ if $@;
    print $OUT $res, "\n" unless $@;
    $term->addhistory($_) if /\S/;
}

When I press the Delete key, program ends immediately. Is this how the thing supposed to work? How to avoid this behavior?

(BTW, this only happens with Term::ReadLine::Perl. After I install Term::ReadLine::Gnu, everything is fine).

  • Comment on Pressing Delete key ends Term::ReadLine loop

Replies are listed 'Best First'.
Re: Pressing Delete key ends Term::ReadLine loop
by Athanasius (Archbishop) on May 20, 2014 at 16:10 UTC

    When I run this code, pressing Delete (or Esc, or Backspace) has no effect on the loop. In fact, the only way I’ve found to exit the loop (without killing the whole script) is to enter Control-Z. So I’m fairly confident that the behaviour you’re seeing is not how the module is supposed to work.

    My system: Windows 8.1 64-bit, Strawberry Perl 5.18.2 64-bit multi-threaded, Term::ReadLine 1.14, Term::ReadLine::Perl 1.0303, Term::ReadLine::Gnu not installed.

    Have you tried re-installing Term::ReadLine and Term::ReadLine::Perl?

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Re: Pressing Delete key ends Term::ReadLine loop
by cord-bin (Friar) on May 20, 2014 at 17:30 UTC
    I always use Term::ReadLine in conjunction with Term::Readline::Perl and Term::ReadLine::Gnu, the first one creates an interface for the others and is recommend to install all of them. Here’s a nice shell you can have with Term::ReadLine
    use Term::ReadLine; my $shell = Term::ReadLine->new('myshell'); $_ = $shell->Features(); my $history = ${%$_}{autohistory}; $SIG{INT} = 'IGNORE'; while(1) { my $return; $command = $shell->readline('myshell> '); { local $SIG{INT} = sub {die 'End';}; $return = eval($command); } if (!$history) { $term->addhistory($_) if /\S/; } }
    You could play with :
    myshell> @test = (a,b,c,d) myshell> print "@test"; myshell> a b c d
    or
    myshell> open OUT, '>/tmp/test'; myshell> print OUT "Hello world !"; close OUT
Re: Pressing Delete key ends Term::ReadLine loop
by zentara (Cardinal) on May 20, 2014 at 17:15 UTC