Filtering Files

CGI scripts are good at changing an existing static files to add dynamic content.

Script II.2.1: naughty.pl

 #!/usr/local/bin/perl
 # Script: naughty.pl

 use CGI ':standard';
 $file = path_translated() || 
	die "must be called with additional path info";
 open (FILE,$file) || die "Can't open $file: $!\n";
 print header('text/plain');
 while (<FILE>) {
    s/\b(\w)\w{2}(\w)\b/$1**$2/g;
    print;
 }
 close FILE;

What it Looks Like

The original file
http://localhost/handout.txt
The filtered file
http://localhost/cgi-bin/conference/naughty.pl/handout.txt

<< Previous
Contents >> Next >>

Lincoln D. Stein, lstein@cshl.org
Cold Spring Harbor Laboratory
Last modified: Sat Aug 21 13:32:16 PDT 1999