> Here's the code I've written:
> 
> Class server
> 
> def read_nagiosstatus(filename)
>   nagios_status = {}
>   for line in IO.readlines(filename):
>     line.strip!                         # Remove all extraneous
> whitespace
>     line.sub!(/#.*$/, "")               # Remove comments
>     next unless line.length > 0         # check for end of file
>     var, value = line.split(/\s*=\s*/, 2)
>     nagios_status[var.intern] = value
>   end
>   return nagios_status
> end
> 
> nagiosstatus = read_nagiosstatus("status.dat")
> puts "Host name is #{nagiosstatus[:host_name]}"
> puts "Service description is #{nagiosstatus[:service_description]}"

So this code actually works. It reads through my key=value pairs just 
fine. But of course, there's no code here to separate between multiple 
instances of {}.

I understand now how to split on {} thanks to the examples you've all 
posted.

What I don't understand though, is how would I address or list these? 
I've got two problems to solve.

The first is that I'd be happy if I could just get an object that was 
unique based on the host_name and I could call 
nagios_status[(:host_name,:plugin_output)] for each  host in the 
status.dat file.

The second is that each host_name has multiple services. My unique key 
needs to be based on the host_name variable. And I think I need to end 
up so I have an object that's like host_name.service_name.variables.




def read_nagiosstatus(filename)
  nagios_status = {}
  for line in IO.readlines(filename):
    line.strip!                         # Remove all extraneous 
whitespace
    line.sub!(/#.*$/, "")               # Remove comments
    next unless line.length > 0         # check for end of file
    var, value = line.split(/\s*=\s*/, 2)
    nagios_status[var.intern] = value
  end
  return nagios_status
end

nagiosstatus = read_nagiosstatus("status.dat")
puts #{nagios_status[:host_name]}

-- 
Posted via http://www.ruby-forum.com/.