From: dblack@... Date: 2002-11-24T21:25:49+09:00 Subject: Re: Ruby idom needed Hi -- On Sun, 24 Nov 2002, Robert Cowham wrote: > What's the best ruby idiom for the following Perl: > > open(EMAIL, "<$EMAIL_FILE") or die "Failed to open $EMAIL_FILE"; > my %hash = map {chomp; split /\=/} (); > close (EMAIL); > > (the above reads a file containing text like > > key1=value1 > key2=value2 > > into a hash. > > So far I have: > > h = {} > f = File.open("fred.ini", "r") > f.each_line{|l| s = l.chomp.split("="); h[s[0]] = s[1]} > f.close A couple of possibilities: 1. h = Hash[*File.new("fred.ini").read.split(/=|\n/)] 2. h = {} File.new("fred.ini").each {|l| h.update(Hash[*l.chomp.split("=")])} David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav