Most text editors today offer complex macro facilities that are often very useful to lighten the burden of repetitive tasks like: It's often quite easy to learn the macro language embedded in your editor, and it gets even easier when it simply offers a "Record" button to write your macro. On the other side, most macro system I have come across are severely limited in the flow rules area, and this limits them severely for use in tasks that are simple but not exactly trivial. A real programming language, or better a scripting language with extensive string support like Perl, will do in many cases; but sometimes the edit-debug-compile cycle seems rather overkill for something you can do by hand in a matter of minutes. Also, writing a simple program to execute your task will require opening a number of files in your editor (at least one for the program and one or more for the data to be processed) and this might be perceived as too much of a chore.

I have come across an easy way to add Perl to a common editor like UltraEdit in a way simple enought to require only one file to be edited. The same idea applies to nearly any text editor that is able to invoke an external program, though I'll give details for UltraEdit only. It is of course a mandatory prerequisite that you have a version of Perl installed on your machine before you try this.

In UltraEdit, go to the "Advanced/Tool configuration" menu and set the program to execute Perl with the current editing file by entering:

  • Command line: perl %F
  • Command output: check 'Create new file' and 'Capture output'
  • Set Menu item name as 'Perl current file'
Then prepare a text file like the following (this creates a set of HTML INPUT elements given space-separated name and value couples on each line):

while () {
	my ($a, $b) = ($1, $2) if /^(.+?)\s(.*)$/;
	print "$a: <input name='$a' value='$b'> <br>\n";


When you then execute the external program by going to "Advanced/Perl current file", the file above will be saved and executed and its output loaded in a new window, where you'll find the exact snippet of HTML you were looking for.

Note how we managed to put the Perl code and the data it's working on in one single file: Perl will stop parsing the program body if it encounters the __END__ statement, and will automatically open a file handler called DATA for the rest of the text file. This behaviour is in our case very handy so we don't have to deal with a separate data file.

You can substitute the my ($a, $b)= .... line with anything to suit your needs, including complex decision making rules if that's what you need. When you get your environment properly configured, you'll notice that it takes a matter of seconds to use this way of scripting, with a total cost that's quite similar to the embedded macro system.

Log in or register to write something here or to contact authors.