Program works in irb, but not in script

Hey folks,

Apologies if this is a very extreme utterly really nubie question, but I
am
trying to learn Ruby and have run into a bit of a snag with a small
program
that attempts to define a method with four variables. The program fails
with the following error message:

zoom.rb:4:in open': Connect failed (10000) z3950.loc.gov (RuntimeError) :7090 from zoom.rb:4:inzoomreturn’
from zoom.rb:21

What’s weird is that if I go through irb and type in the entire method
def
and then supply it with four variables, the program works. So I’m
pretty
stymied.

The program is below. Note that the “zoom” stuff I’m referring to in
here
is a particular protocol that queries library catalogs. The ruby module
for
it is at http://ruby-zoom.rubyforge.org

If anyone wants to try it themselves to see, try using the following
variables for server, dbname, syntax, isbn:
z3950.loc.gov
Voyager
USMARC
0253333490

If it works correctly, the method should return a MARC record
(basically, an
electronic library card) about a book on dinosaurs.

Thanks for taking a look,

jf.


require ‘zoom’

def zoomreturn(server, dbname, syntax, isbn)
ZOOM::Connection.open(server, 7090) do |conn|
conn.database_name = dbname
conn.preferred_record_syntax = syntax
rset = conn.search(isbn)
p rset [0]
end
end

puts “Server:”
server = gets
puts “dbname:”
dbname = gets
puts “Syntax:”
syntax = gets
puts “isbn:”
isbn = gets

zoomreturn(server, dbname, syntax, isbn)

“J” == John F. [email protected] writes:

Try it with

J> puts “Server:”
J> server = gets

server = gets.chomp

J> puts “dbname:”
J> dbname = gets

dbname = gets.chomp

J> puts “Syntax:”
J> syntax = gets

syntax = gets.chomp

J> puts “isbn:”
J> isbn = gets

isbn = gets.chomp

Guy Decoux

Holy moley, that works. Retrospectively, what a completely dumb thing I
did. Of course zoom would choke on newlines. Buh. Guy, thanks a ton;
I
appreciate it.

jf

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs