Here's my bit of clean-up on the first one, which I will be happy to
elaborate on if you'd like. Let me know what you think.
#!/usr/bin/env ruby
class MyEnd < Exception; end
begin
myfile = open('phonespec.txt', 'a')
closing = "\n\nTo start the program again please type intro2.rb\n\tGood Bye!\n\n"
enterFirstName = "" #First Name in the addressbook
enterLastName = "" #Last Name in the Addressbook
enterPhoneNumber = "" #Phone Number in the addressbook
print "Welcome to MyAddressbook. Please follow the prompts.\n"
"If you wish to end data entry, you may do so at any time\n"
"by type the word END into a prompt.\n"
STDOUT.sync = true
getLine = lambda {
l = STDIN.gets
l.chop!
if l == "END"
raise MyEnd
else
l
end
}
loop {
print "\n\tFirst Name: "
enterFirstName = getLine.call
print "\n\tLast Name: "
enterLastName = getLine.call
print "\n\tPhone Number: "
enterPhoneNumber = getLine.call
myfile.write([enterFirstName, enterLastName,
enterPhoneNumber].join("\t") + "\n")
}
rescue MyEnd
print closing
ensure
myfile.close
end
--
Brian Fundakowski Feldman \ FreeBSD: The Power to Serve! /
green / FreeBSD.org `------------------------------'