From: Warren Brian Noronha Date: 2003-04-03T14:53:46+09:00 Subject: Re: eval'ing a config file dear ian, there is a very good project on raa called xml-config i suggest you check that out. regards warren brian noronha warren@freedomink.org On Wed, 2 Apr 2003 02:15:15 +0900 Ian Macdonald wrote: > 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 | > | > >