From: Ross Shaw Date: 2002-11-24T21:21:39+09:00 Subject: Re: Ruby idom needed In article , 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 > > h = {} File.foreach("fred.ini") do |line| key, value = line.chomp.split("=") h[key] = value end Ross