From: m b Date: 2011-06-14T03:05:46+09:00 Subject: Re: Regexp.match(line) question --_97fbc2f2-1a1a-47df-aaa4-483a447a87e1_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable > > if I do this: > > > > f=3Dopen('filename.dat'=2C'r') > > str=3Df.read > > > > and then: > > > > str.each_line do |line| > > /ruby/.match(line) > > > > ruby prints out variable line and say its a RegexpError > > 'empty range in character class' as if it interprets line as a Regexp > > What am I doing wrong? There are a lot of strange characters in variab= le line=2C > > maybe that is the issue? >=20 > I'm not sure about the issue=2C but the usual idiom for this is: >=20 > File.foreach("filename.dat") do |line| > line.match(/ruby/) > end >=20 > This way: > - The file handler is automatically closed for you=2C you don't have to > ensure that you call close on it=2C it's done for you. > - You only have one line at a time in memory=2C since that seems to be > your unit of data. If the file is huge it will make a difference in > the amount of memory you will consume at a time. >=20 > In any case=2C String#match calls Regexp#match=2C so calling match on one > or the other should make no difference. Can you show a small example > of a file that breaks? >=20 > Jesus. Aha.. Thats a better way to do it.. File.foreach Thanx. the string-variable line both starts and and ends with a '/' . Its = a series of paths from a linux system hd =20 But its a String to be searched and not a Regexp = --_97fbc2f2-1a1a-47df-aaa4-483a447a87e1_--