JDT

 

FREE Downloads
Articles
Tutorials

 

Running a Perl Script from TextPad


TextPad® from Helios Software Solutions has been my text editor of choice for quite a while now, and I have developed many websites and applications using it.

There are plenty of reasons why I like it, but one thing I particularly find useful is the ability to run a command/program from within the editor itself. In this tutorial I'll show you how you can run a Perl script from within TextPad that processes the document that is currently active in TextPad.

Perl and the Perl Script

The first thing you need to do is to identify where Perl is installed on your computer. If it's not installed, then you need to install it. You also need to put the Perl script itself into Perl's 'bin' folder. Typically, the path to perl.exe and the script will be:

C:\Perl\bin\

Running perl.exe and the Script from TextPad

Next, you need to add perl.exe as a program that can be run from within TextPad, and the Perl script as a parameter. To do this:

1. Select Preferences... from the Configure menu.

2. Click Tools.

3. Click Add and then Program.

4. Browse to, and select, perl.exe.

5. Click Apply. This adds Perl to the list of Tools.

6. Click Perl from under Tools in the left-hand pane. The dialog box will look something like:

7. Edit the settings so that they are typically as shown here:

Note that the name of the script itself needs to be in the Parameters line. In this example, the name of the script is RemoveRedText.pl.

8. Click Tools and then click Perl.

9. Change the name (Perl) to something meaningful, as shown below, and click OK.

Running the Script

To run the script, select it from the Tools menu. It will process the document that is currently active in TextPad.

Sample Script

Here is a sample Perl script that will work for the above setup.

RemoveRedText.pl

foreach $name (@ARGV)

{

# make a backup of file before fixing
rename $name, "$name.bak" or die "cannot rename: $!";
open (IN, "<$name.bak") or die "cannot open: $!";
open (OUT, ">$name") or die "cannot create: $!";

# read in the whole file
undef $/;

# work through each line in the file
while ($line = <IN>)

{
$line =~ s/<li class="red">/<li>/gsi;
$line =~ s/<li class=red>/<li>/gsi;

# write output file
(print OUT $line);

close (OUT);
close (IN);
close (FILE);

}
}

# remove temporary files
{

unlink (<*.bak>);
}







Go back to Perl Tutorials home page

Go back to Tutorials home page



Earnings Tracker is an easy-to-use FREE open source accounting / bookkeeping software tool aimed at contractors, freelancers, and other very small businesses.

The software enables invoice amounts, salaries, expenses, pension contributions, and bank interest to be recorded, and calculates the amount of VAT and corporation tax due. The software also enables dividend tax vouchers to be generated.

Earnings Tracker is written in PHP and MySQL and is available to use for FREE online, or as a FREE download.

Earnings Tracker can also be used simply as a dividend, corporation tax, or VAT calculator.

Need free accounting software
 



JDT

Copyright Notice for John Dixon Technology Ltd

Privacy Statement

Terms & Conditions