Slash Boxes
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 ]

bart (450)

Journal of bart (450)

Friday September 29, 2006
03:27 PM

Rough idea: paste using templates in a text editor

[ #31165 ]
I sometimes get one of those little ideas while banging away on the keyboard, in the realm of "wouldn't it be nice if...". Usually, I forgot about them the next day and I rarely, if ever, think of it again... Or at the least, not for a few months. I can't ever think of those little ideas when people ask me what kind of features I'd like... So now, I'll write it down. As a reminder to myself, or maybe a bit of inspiration to you, who knows.

Today, I was trying to write down an SQL insert statement. It took a huge amount of time, mainly because how it needs to be typed is so different from what it is based upon and yet it's so very strictly coupled syntaxwise. Let me give an example. The statement could be something in the form of:

insert into bloob (a, b c) values (x, y, z);

Simple, no? until the field names and values are not so simple any more.

Usually, the source is a description of a database table. Suppose you can get it into a form of tab delimited rows separated by newlines. In short: a plain tab delimited file. For this file the structure would look like:

a        x
b        y
c        z

All pretty standard, and likely, it's quite easy to get the data from other sources into this shape, using standard tools.

Now, what I'd like to be able to, is to paste this data into the shape of the SQL statement, plain and simple. That is: it should make use of a template like, for example

insert into $table (@fields) values (@values)

given that array items would be joined by a comma (can be parameterized) and that there's a way to link the variables to the source data fields. It would be nice if extra formatting could be applied to each array item (as if with map) before it gets inserted such as wrapping quotes around them.

How? I don't know. I haven't thought that through yet.

And no, I don't want to write a dedicated little script to do each specific case for me.

If, by any chance, you know of an editor that has this or a similar feature, I'd like to know about it.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • One could also use this alternative: select a piece of text, and apply a template to it. That could, for example, be used to replace an URL by a html link, thus replacing



    <a href="http://use.perl/org/">http://use.perl/org/</a>

    with the default text (here the URL) selected, ready to be overtyped by a different text.

    Or, supposing you have the database table data, formatted as described in the root post, as part of the text document, and you can select it, and apply the S