From: "David A. Black" Date: 2005-09-14T12:19:25+09:00 Subject: Re: strings and regex's Hi -- On Wed, 14 Sep 2005, jdm wrote: > I'm parsing some html and have a table-driven state machine that configures > itself by reading tuples (one per line) of "present state", "pattern to match", > and "next state" with this code: > > lineArray=Array.new() > stateTable=Hash.new() > > File.open("stateTable.txt") { |file| > file.each { |line| > lineArray=line.scan(/[^\s]+/) > stateTable[lineArray[0]]=lineArray[1..-1] > } > } > > I've printed this hash out in several different ways with the same results: the > key-value pairs look as expected (no extraneous spaces, newlines, etc.). Once > the hash is set up, it drives a state machine with this code: > > 1 state="html" > 2 while input=gets() # text lines are the s.m.'s "clock" > 3 if input.chomp().length>0 # skip blank lines Is it possible that you need chomp! instead of chomp ? I'm not sure what the regex looks like that you're testing it against later, but if it doesn't allow a terminal \n then that may be the problem. David -- David A. Black dblack@wobblini.net