Peter Loftus wrote:
> Got help with this code earlier its just checking a file for a line
> 
> Im really new to ruby ive used java and C before
> 
> just wondering what do i put in if i want to use a variable that is
> holding the string eg VAR1 = "hello"
> 
> File.foreach "file.txt" do |line|
>   if /hello/ =~ line
>     puts "found it"
>     break
>   end
> end

var = "hello"
File.foreach "file.txt" do |line|
  if /#{var}/ =~ line
    puts "found it"
    break
  end
end

Perhaps?

Regards,
Lee
-- 
Posted via http://www.ruby-forum.com/.