Click to See Complete Forum and Search --> : Getting Perl script to work with cgi.......


PegLegBoy
06-11-2001, 07:22 PM
I wrote this perl program that parses through comma seperated data. It works fine on the command line. I would like to make it work in CGI so that I can just cut and paste my data into a form. I'm stuck and don't know where to continue. Any help would be appreciated. Thanks.


#!/usr/bin/perl

$row = 1;

while ( <> ) {
@line = split(/,/);
if ($row == 1) {
printf "%-2.2s%-15.15s\n", $line[0], $line[1];
}
if ($row >= 2) {
printf "%-2.2s%-9.9s\n", $line[21], $line[22];
}
else {
$row++;
}
}

Ben Briggs
06-11-2001, 08:47 PM
When writing CGI scripts, you need to send the content type of the message you are about to send (i.e. the program results). For HTML it's:

print "Content-type: text/html\n\n";
# for text
print "Content-type: text/plain\n\n";


The two newlines are important, because it's the MIME type standard.