From: Michael Linfield Date: 2008-05-09T06:10:42+09:00 Subject: Re: wired result Cheyne Li wrote: > Sorry, I wasn't finish when I mistakely posted it. > > I tested > i=0 > line.scan(fkey){|x|i=i+1} > puts i > if i>0 > puts "Found match...\n\r" > end > > in other file by assgined fkey and line. it worked > > but the function itself couldn't find match at all. I have no idea > what's wrong with it. Is there anyone can help me out? Thanks a lot If I'm understanding you correctly, you have lets say an array of keys you want to find in a file. fileKeys = ["key1","key44","key5"] lets just say the file contains a bunch of useless jargon and some keys: testfile.txt # stuff more stuff key5 useless junk more useless junk not a key key44 Ok, now lets read that file and put the keys in an array called results results = [] IO.foreach("testfile.txt") {|x| results << x.chomp} => nil Now we compare the arrays to find any matches results&fileKeys => ["key5","key44"] Regards, - Mac -- Posted via http://www.ruby-forum.com/.