From: Paul Lutus Date: 2006-09-27T02:55:14+09:00 Subject: Re: Ruby's equivalent of PHP explode James Edward Gray II wrote: > On Sep 26, 2006, at 11:15 AM, Paul Lutus wrote: > >> As to the second, read an .ini file and break it down by line and by >> name/value pairs (not tested): >> >> data = File.read("filename.ini") >> >> my_hash = {} >> >> data.each do |line| >> key,value = line.split("=") >> my_hash[key] = value >> end > > No need to slurp a file so we can process it line by line. Yes, true, this is an old habit of mine dating from the days of floppy drives as data sources (mechanical wear issues), but obviously with large files, a potential source of difficulty. > Also, the > equals-in-value problem is just one more argument to split(): > > ini = Hash.new > > File.foreach("file_name.ini") do |line| > key, value = line.split("=", 2) Thanks! Hadn't seen this syntax. -- Paul Lutus http://www.arachnoid.com