From: Jim Freeze Date: 2002-11-25T11:24:40+09:00 Subject: Re: Ruby idom needed On Monday, 25 November 2002 at 11:02:41 +0900, Damon wrote: > Ross Shaw wrote in message news: 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. > > > > > h = {} > > File.foreach("fred.ini") do |line| > > key, value = line.chomp.split("=") > > h[key] = value > > end > > Would this be better if you changed split to: key, value = line.strip.split(/=/,2) That way, you could handle things like key1 = Fred = 2 #=> 'key1' => "Fred = 2" -- Jim Freeze ---------- Nothing is faster than the speed of light ... To prove this to yourself, try opening the refrigerator door before the light comes on.