On 16 Nov 2007, at 17:07, Feng Tien wrote:

>> Alex Gutteridge
>
>
> Yah, I'm use the Enumerable#grep
>
> Here's what I'm trying to do
>
> def literal (search_term, *inputs)
>    inputs.each do |to_search|
>      puts open(to_search).grep(search_term)
>  end
> end
>
>
> When I run that method, it just gives me an blank screen, while using
> Regexep(search_term), i get results.
>
> How do I get an exact match?

Perhaps there's a line ending "\n" you're missing. Your method works  
for me below if I remember the line endings:

[alexg / powerbook]/Users/alexg/Desktop(8): echo 'foo' > foo.txt
[alexg / powerbook]/Users/alexg/Desktop(9): echo 'bar' > bar.txt
[alexg / powerbook]/Users/alexg/Desktop(10): echo 'foobar' > foobar.txt
[alexg / powerbook]/Users/alexg/Desktop(11): irb
irb(main):001:0> files = ['foo.txt','bar.txt','foobar.txt']
=> ["foo.txt", "bar.txt", "foobar.txt"]
irb(main):002:0> def literal(search_term, *inputs)
irb(main):003:1> inputs.each do |to_search|
irb(main):004:2* puts open(to_search).grep(search_term)
irb(main):005:2> end
irb(main):006:1> end
=> nil
irb(main):007:0> literal('foo',*files)
=> ["foo.txt", "bar.txt", "foobar.txt"]
irb(main):008:0> literal(Regexp.new('foo'),*files)
foo
foobar
=> ["foo.txt", "bar.txt", "foobar.txt"]
irb(main):009:0> literal("foo\n",*files)
foo
=> ["foo.txt", "bar.txt", "foobar.txt"]

Alex Gutteridge

Bioinformatics Center
Kyoto University