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

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.
  • by djberg96 (2603) on 2003.03.17 13:09 (#17991) Journal
    I admit it - I've hardcoded sql into my programs before, though I haven't done it in any *major* programs - just short scripts.

    What I do now is keep the sql in a separate file, occasionally using a special comment so I can slurp the sql into memory (in paragraph mode) and use the special comment as a hash key (with the sql as the value for that key) so I don't have to remember the order of the sql. e.g.

    --0 some query
    select foo from bar where foo = 1

    --1 another query
    select baz from bar where baz = "Y"
    Then after slurping the file, I end up with a hash that looks like:
    $sql_hash{
       0 => 'select foo from bar where foo = 1',
       1 => 'select baz from bar where baz = "Y"'
    }
    The other advantage of having the sql separated is that you can do separate version control for that file, and change the sql without having to rerelease the calling script. Probably obvious - just thought I'd mention it for anyone else. :)

    Depending on my needs I don't always do the hash trick thing. Or am I doing things totally stupid? Gonna post your talk afterwards? I'd like to read it.