#!/usr/bin/env ruby require 'cgi' $KCODE = 'e' cgi = CGI.new("html4") print("Content-type: text/html; charset=EUC-JP\n\n") register = Hash.new familyname = cgi["surname"] forname = cgi["givenname"] areacode = cgi["area"] code1 = cgi["former"] code2 = cgi["latter"] open("phone.txt", "a") do |list| list.printf("%s\t%s\t%s\t%s\t\%s\n", familyname, forname, areacode, code1, code2) end #system("cat phone.txt") open("phone.txt", "r") do |file| while data = file.gets if /(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/ =~ data person = $1 + $2 phone = $3 + "-" + $4 + "-" + $5 # 文字列 + 文字列 で文字列をつなげる register[person] = [phone] end end end print("\n") print("
\n") print("\n") printf("ご芳名: %s\n", people) print("
\n") print("\n") printf("連絡先: %s\n", register[people]) print("
\n") end print("\n") print("\n")