Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Robrt (1414)

Robrt
  (email not shown publicly)

robert at perl dot org

Journal of Robrt (1414)

Wednesday November 27, 2002
11:50 PM

First Principles

[ #9191 ]
For the past few months, on and off, I've been working on a new search interface for one of my favorite tools. The fun part - I wanted it to be a naturalish query language, SQL based. (So, it would be SQL-like => Internal Object Representation => Real SQL).

I've tried many things, from SQL::Statement to Parse::RecDescent. I looked at Parse::Yapp, and even considered shishi. What did those modules get me? A lot of frustration.

This afternoon, after another losing bout with Parse::RecDescent, I threw up my hands.

At that point, I went back to first principles and wrote a simple tokenizer. In goes the SQL, out comes some standardized tokens. The best part? It was easy. Regexp::Common helped with quoted strings, and I was in the home stretch. A simple state machine later, and I had a working SQL-like search tool.

Lesson: Sometimes a pre-existing modules isn't the way to go. It can overcomplicate things and make you work in the wrong direction. KISS works!

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • like the Text::Query package [cpan.org], which seems to describe itself as solving a similar problem?
    --
    • Randal L. Schwartz
    • Stonehenge
  • I came across something recently that questioned the wisdom of not reinventing wheels. I can't remember where I read it, but it the tone was something like "reinventing wheels can be a good thing". The justification was that not every problem is identical, and we need problem solvers much more than we need solutions in search of a problem.

    I'm pretty sure it wasn't referring to the pathological case of templating modules on CPAN though. :-)

    In any case, I'll try and find a citation, but it's going to be

  • I didn't know about Text::Query, but it wouldn't do the job, because I need a tool that can do algebraic combinations of [key op value] triplets. It also suffers, like many many other modules, from anti-documentation-itis. But anyway, my wheel is round enough for now.