Filtering a file via a Perl script

 
Post new topic   Reply to topic    Aprelium Forum Index -> Perl
View previous topic :: View next topic  
Author Message
toms
-


Joined: 24 Jun 2004
Posts: 1

PostPosted: Sat Jun 26, 2004 4:40 am    Post subject: Filtering a file via a Perl script Reply with quote

I would like to run a Perl script whenever a pattern matches a file being served from htdocs.

For example if 'htdocs/try.txt' is being served I would like 'cgi-bin/filter.pl' to run first, read/filter 'try.txt', print a header, and then output the result to the browser (see below).

I tried setting up an interpreter 'cgi-bin/filter.pl', associating it with 'txt', and a path of '/*.txt' but can't get it to work.

I know this can be done with SSI but if this works then I should be able to use Abyss with HTML::Mason which is much more capable.

Am I missing something obvious?

Thanks,
Tom

Code:

----------------------------------------------
filter.pl
----------------------------------------------


#!c:\perl\bin\perl.exe

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');
print "\n\n";
print "Filter.pl did this.\n\n";

while (<FILE>) {
   print;
}
close FILE;
Back to top View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Sun Jun 27, 2004 12:18 pm    Post subject: Re: Filtering a file via a Perl script Reply with quote

toms,

You script seems to rely on PATH_TRANSLATED CGI variable. Assuming you have a text file in http://yoursite/dir/text.txt and your script is in http://yoursite/script/filter.pl, you should browse http://http://yoursite/script/filter.pl/dir/text.txt to have this script filter the file.
You can of course include the result of this processing in an SSI file but this isn't required.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> Perl All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group