Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI script containing regular expressions

Status
Not open for further replies.

weloki

Technical User
Feb 19, 2004
12
US
I have a perl file that contains some regular expressions, and I want to make it into a CGI script. Can something like this run on the web so that when the user points to it with their browser it will execute the perl file and deliver the results of the search and replace? Every time I try it gives the message "Internal Server Error."
Below is a shortened version of my file:

#!/usr/bin/perl -w
use CGI qw:)standard);
print "Content-type: text/html\n\n";

use diagnostics -verbose;
use warnings 'all';
#use re 'debugcolor';

package XMLtoRDFConverter;

#input XML elements:
$e = "
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<!DOCTYPE #... more xml stuff...
";

if ($e =~ m/<!DOCTYPE/)
{$e =~ s/<!DOCTYPE(.*?)>//s;
print ("");}
else {print ("no doc type declaration\n");}

#more regular expressions...

open FH,">rd.txt" or die $!;
print FH $e;
print ("$e\n");
 
If you run it from the command line does it give any errors. Can you check your web log to see more details of the Internal Server Error

--Paul

Nancy Griffith - songstress extraordinaire,
and composer of the snipers anthem "From a distance ...
 
Paul, thanx for the reply. I had some help with it and it turns out that the code needed to be changed a bit. Here is a solution that worked:

#!/usr/bin/perl
use strict;
use warnings;

use CGI;
use CGI::Carp qw/fatalsToBrowser/;

my $q = new CGI;
print $q->header('text/plain');

#input XML elements:
my $e = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<!DOCTYPE #... more xml stuff...>";

if ($e =~ m/<!DOCTYPE/) {
$e =~ s/<!DOCTYPE(.*?)>//;
print "Happy Day\n";
} else {
print "no doc type declaration\n";
}

#more regular expressions...
#open FH,">rd.txt" or die $!;
#print FH $e;
print "$e\n";
#close FH;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top