From: Matt Armstrong Date: 2002-12-14T05:48:19+09:00 Subject: Re: Splitomania - advice welcome Anders Engstr�m writes: > Hi. > > I'm writing a commitinfo script for CVS using ruby 1.6.7 on Debian > Woody. I've created a class that handles all the ugly stuff at a commit, > and the actual commitinfo-scripts uses this class to ease the CVS > interaction. > > Now - I want to extract the editors of each file that gets commited. > This is done by parsing the $CVSHOME/CVS/fileattr file. I want to get > all editors as a Hash where the keys are the names of the editors, and > the values are the extra info for the editor. The file format of > $CVSHOME/CVS/fileattr is something like: > > Fname_of_fileattribute_name=attribute_value[;attribute_name=attribute_value...] > > the attribute containing the editors looks like: > > _editors=name_of_editor>time+hostname+pathname[,name_of_editor>time+hostname+pathname...] I suspect the ugly code reflects the ugly file format you are parsing. Here is my untested attempt. editors = Hash.new File.open("fileattr") { |line| fname, attrs = line.split("\t", 2) attrs.split(";").each { |attr| next unless attr =~ /^_editors=(.+)/ $1.split(",").each { |editor| name, stuff = editor.split(">") editors[name] = stuff } } } If your 'if' statements are for catching file format errors, you might replace them with a begin/rescue/end within the loop. But that can hide bugs in your own code. File.open("fileattr") { |line| begin fname, attrs = line.split("\t", 2) attrs.split(";").each { |attr| next unless attr =~ /^_editors=(.+)/ $1.split(",").each { |editor| name, stuff = editor.split(">") editors[name] = stuff } } rescue end } -- Don't send mail to Rod_Smith@hole.lickey.com The address is there for spammers to harvest.