Subj : binktrim in ruby To : All From : tony summerfelt Date : Wed Feb 04 2004 04:34 pm this is the binktrim program in ruby. i'm not happy with it. this took me WAY longer to write than the perl version. ruby's 'principle of least suprise' turned out to be the 'principle of most suprise' ruby does not have perl's magic. it could be that i was trying to write it too perlish, but for a quick and dirty script i should have had to fiddle with classes, etc. the output isn't quite what i wanted (you'll see if you compare the perl trimmed file to the ruby trimmed file.) the only advantage i can see with the ruby version is the parse method for Time. and the program is definitely slower. i think for larger oo projects i would stick with itcl or ruby, probably not perl, and definitely not python. ========================================================================== require 'time' require 'tempfile' require 'ftools' if ARGV.length!=2 raise "usage: binktrim " end year=Time.now.year t2=Time.now t=Tempfile.new("trimmed") l=File.open(ARGV[0]) l.each_line {|line| logline="#{line}" if line=~/\[\d+\]/ if line=~/\[\d+\]/ td1=logline.split(/\[\d+\]/) td2=td1.first.split(/\s+/) td2.delete_at(0) td2.push(year) td3=td2.join(s=" ") t1=Time.parse(td3) t3 = t2 - 24 * 3600 * ARGV[1].to_i t.print("#{logline}") if t1>t3 end t.print "#{line}" if line=~/^\s*$/ } l.close File::copy(t.path, ARGV[0]) t.close(true) ========================================================================== --- GoldED/spleen 3.0.1-os1+ * Origin: ventedspleen.dyndns.org (1:261/38.5) .