Everything2
Near Matches
Ignore Exact
Full Text
Everything2

Add Perl to your favorite text editor

created by lenz

(idea) by lenz (2.6 wk) (print)   ?   (I like it!) Mon Oct 20 2003 at 12:12:44

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";
}
__END__

FIELD_1 X
FIELD_2 Y
FIELD_3 Z

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.


printable version
chaos

Add One to Cobol Get a real computer! A word processor is not a text editor Emacs
compile ultraedit Perl OLE edit
Why bother? text editor Trivial TextPad
writeup unix2dos color Scintilla
data Lingua::Romana::Perligata CPAN macro
scripting language Rexx Perl debug
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
What you are reading:
Fuel rationing
Onion
Sally
Things Fall Apart
Breaking the Vigenère Square
Surviving a long-distance plane flight
Palm Beach County's Screwed Up Ballots
Home Life in Ancient Greece
The Monster at the End of This Book
Confessions of an ass-kicker
Mothman
Red Headed Stranger
Reading Motivation
New Writeups
edteach
Jehovah's Witnesses(person)
calgon
The release of being useful(poetry)
cassandra882
rooted tree(idea)
Nadine_2
little green men(recipe)
gin soaked
Lavender braised chicken(recipe)
DejaMorgana
Briefcase Full of Souls - Part I(person)
tentative
What is it with chicks and horses?(idea)
vandewal
Adventures on the Plains(place)
Rai Tai
August 8, 2008(idea)
Alnilamski
Rebel Yell(thing)
Heisenberg
Dahon Speed D7(thing)
etgar
Protection of civil rights in the USA and UK(essay)
archiewood
Airspace classifications(idea)
Ouzo
My first Christmas(event)
TheDeadGuy
Editor Log: August 2008(log)
This affordable entertainment brought to you by The Everything Development Company