Gnu readline ruby vs. perl

I'm translating a Perl script into Ruby, but can't reproduce a readline
action. I made two, hopefully equivalent, test scripts in Perl and Ruby,
but they behave differently.

Here's my Perl script:

    #!/usr/bin/perl
    use Term::ReadLine;
    
    # count lines in stdin (the mail message):
    $n=0; while (<>) { $n++ }
    print "$n lines\n";
    
    my $term=new Term::ReadLine 'vpp';
    $term->readline("type return to quit: ")

And here the test run:

    $ echo test |readlineperl
    1 lines
    type return to quit:
    $

Now the Ruby version:

    #!/usr/bin/env ruby
    
    require 'readline'
    include Readline
    
    # count lines in stdin (the mail message):
    n=0; while gets: n+=1 end
    puts "#{n} lines"
    
    readline("type return to quit: ")

Its test run does not exit with a return - it needs ctrl-C:

    $ echo test |readlineruby
    1 lines
    type return to quit:
    ./readlineruby:10:in `readline': Interrupt
            from ./readlineruby:10
    $

Is this a bug? Or a missing feature, like Readline.new?

···

--
Wybo

Hi,

···

In message "Re: gnu readline ruby vs. perl" on Fri, 10 Jun 2005 07:19:45 +0900, Wybo Dekker <wybo@servalys.nl> writes:

I'm translating a Perl script into Ruby, but can't reproduce a readline
action. I made two, hopefully equivalent, test scripts in Perl and Ruby,
but they behave differently.

Ruby's readline takes input from stdin. Perhaps Perls takes from
/dev/tty, or something. Any information is welcome.

              matz.

Hi,

At Fri, 10 Jun 2005 07:19:45 +0900,
Wybo Dekker wrote in [ruby-talk:145011]:

Its test run does not exit with a return - it needs ctrl-C:

    $ echo test |readlineruby
    1 lines
    type return to quit:
    ./readlineruby:10:in `readline': Interrupt
            from ./readlineruby:10
    $

The test exited immediately after printing the prompt, on my box.
What are your platform, ruby and readline versions?

···

--
Nobu Nakada

I've experienced same problem with OP.

$ ldd /usr/lib/ruby/1.8/i686-linux/readline.so | grep readline
        libreadline.so.4 => /lib/libreadline.so.4 (0xb7f00000)
$ ruby -v
ruby 1.8.2 (2004-12-25) [i686-linux]

Same on the 1.9 (March).

···

On 6/10/05, nobuyoshi nakada <nobuyoshi.nakada@ge.com> wrote:

The test exited immediately after printing the prompt, on my box.
What are your platform, ruby and readline versions?

--
http://nohmad.sub-port.net