Ross Shaw <rshaw1961 / yahoo.com.au> wrote in message news:<rshaw1961-> Robert Cowham <rc / vaccaperna.co.uk> 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 /\=/} (<EMAIL>); > > 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 > > > > > > h = {} > File.foreach("fred.ini") do |line| > key, value = line.chomp.split("=") > h[key] = value > end > > > Ross Thank you! This is clear and still concise. The other responses seem to gravitate towards Perl-like one-liners. But this defeats the purpose of writing in Ruby---to avoid Perl obfuscations. The above is much more readable and also much more idiomatic than many of the others. This should go into athe Ruby Cookbook (if it were still up).