gnu readline ruby vs. perl

W

Wybo Dekker

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?
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: 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.

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

matz.
 
N

nobuyoshi nakada

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?
 
G

Gyoung-Yoon Noh

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

I've experienced same problem with OP.

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

Same on the 1.9 (March).

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top