Why not use this pattern substitution (instead of gsub! and yield) - line = s/[ \t]*#.*$//; next if /^$/; Not sure how that translates to Ruby.... >>> Dave Thomas <Dave / thomases.com> 03/15/00 02:37PM >>> "David Douthitt" <DDouthitt / cuna.com> writes: > Thanks for the help! Now a question on your alternative: > > >>> Dave Thomas <Dave / thomases.com> 03/15/00 01:36PM >>> > > By the way, there's another fun Ruby trick for doing this kind of > thing. You could code up a simple iterator which only returns > non-blank non-comment lines > > def nonCommentLines(aFile) > aFile.each { |line| > line.gsub!(/#.*/, '') > yield(line) unless line =~ /^\s*$/ > } > end > > File.open(ENV["ORACONF"]) { |conf| > nonCommentLines(conf) { |line| > print line > } > } > > >>>snip!<<< > > Isn't this alternative more costly in terms of time? I know OOP isn't > known for being fast, but.... It also seems to be much more complex - > a yield and gsub! instead of a simple pattern-match. Yup! I think it is. The gsub is there because it has slightly different semantics than your version, skipping any line that consists solely of zero or more spaces after comments are removed. The lines it returns have the comments already stripped, ready for parsing, so db = fred # primary database # (a silly example) # size = 10 # and the size will just return the lines db = fred size = 10 But, as you say, that does come at a cost. However, the benefit of the approach is you now have a reusable method that will strip comments and blank lines from _any_ Enumerable collection of strings (despite the name of the parameter). That may or may not be a big win the next time you have to parse a parameter file. I could be argued either way (and frequently am) Dave