From: Ian Macdonald Date: 2003-04-02T02:15:15+09:00 Subject: eval'ing a config file Hi, I have a number of LDAP-related programs that I want to share a common config file in which certain variables are stored, such as server, port, password, etc. in the following form. LDAP_HOST = foo.bar.com LDAP_PORT = 389 LDAP_PASS = foobar I want the parser to ignore blank lines and those that start with a '#'. The code that I've come up with is this: File.open("/etc/ldaprc") do |f| f.each do |line| next if line =~ /^(#|$)/ var, val = /^(.+?)\s*=\s*(.+)$/.match(line)[1,2] eval "#{var} = '#{val}'" end end It works, but looking at it, it looks too much like code I might have written for Perl some years ago. Is there a more Rubyesque way to do this? In particular, is there a cleaner way than eval? Ian -- Ian Macdonald | Parts that positively cannot be assembled System Administrator | in improper order will be. ian@caliban.org | http://www.caliban.org | |