From: James B Crigler Date: 2004-10-06T03:34:51+09:00 Subject: Re: Table-driven dispatch I like this solution, except it solves the wrong problem. That's my fault because I didn't quite give enough of the problem specification. I have over a thousand individual files to scan, some with a couple of thousand lines. Some fields are not tagged, but ASCII paragraphs, and these can be interspersed with the tagged lines. Also, Robert's solution applies a capturing Regexp to every line of the file. (I didn't specify it, but performance is at a premium here.) I will probably use the part about putting the fields into a local hash as the fields I want are parsed out. Also the tag translation hashes are a nice touch. Consider what happens in Robert's solution when confronted with this (not exactly according to my document specification, but you'll get the idea): ----------- Title: A Tale Of Two Cities Author: Charles Dickens Analysis: There are many different ways of interpreting Mr. Dickens's Title: It is reminiscent of, for instance, the title of St. Augustine's book, The City of God. ----------- (This is easily programmed around (just take the first title, author, whatever).) In the problem I'm trying to solve, I am making ad hoc queries at the command line and turning them into a filter procedure in an eval. I don't know which fields I'll be querying or printing until after filter = eval "proc { |#{mode}| #{filter_expr} }" is evaluated. ("mode" contains the subclass of document, e.g., "novel"; "filter_expr" contains the filter expression (surprise! ;-) passed in from the command line, and it is supposed to contain stuff like "novel.title =~ /city/i" and so on.) A separate bit of command line syntax selects fields to print. -- James B Crigler Voice: (770)494-2077 C-27J Software Requirements Manager Fax: (770)494-3886 Lockheed Martin Aeronautics Company D/6B3M Z/0100 86 South Cobb Drive Marietta GA 30063 "I say, Jerry! You'd be in a Blazing bad way if recalling to life was to become the fashion, Jerry!" -- A Tale of Two Cities