When I run the following code it runs fine.
#!/usr/bin/perl
$in = $ENV{'QUERY_STRING'};
@elements = split /&/, $in;
for $element (@elements)
{$element =~ tr/+/ /; # decode +'s to spaces
($key, $value) = split /=/, $element;
$key =~ s/%([\dA-Fa-f]{2})/pack("C".hex($1))/ge; # decode key
$value =~ s/%([\dA-Fa-f]{2})/pack("C".hex($1))/ge; # decode value
if ($key eq "state") {$state = $value};
if ($key eq "id") {$id = $value};
if ($key eq "dir") {$dir = $value};
if ($key eq "county"){$county = $value};
}
($day, $month, $year) = (localtime)[3,4,5];
$year = $year+1900;
$month=$month+1;
open(logfile,">> test $year $month.txt");
open(trackfile,"datadhqcountybnrs.dat");
while($trackrec = <trackfile>)
{chomp($trackrec);
($trackid,$trackclient,$tracklink) = split(/~/,$trackrec);
if ($trackid eq $id)
{$newrecord = join ("\~",$trackid,$trackclient,$dir,$state,$county,"\n");
print logfile $newrecord;
close(logfile);
close(trackfile);
print "Content-type: text/html\n";
print "Location: [$tracklink\n\n";...]
exit}
}
When I pull out the following lines I get "Premature end of script headers"
print "Content-type: text/html\n";
print "Location: [$tracklink\n\n";...]
I just want to write to the logfile.
Thanks for any help.
Paul
open(logfile,">> /full/path/to/test-$year-$month.txt");
Also, look in your error logs
see if you can find a copy of 'testmy.cgi' on hte internet somewhare and install that in your cgi-bin and runn all your scripts with it.
make sure below is the first 4 lines of your script
#!/use/bin/perl -w
use strict;
use CGI::Carp qw(fatalsToBrowser);
[edited by: Drag_Racer at 11:11 am (utc) on July 23, 2007]
I suspect that when you remove the two header lines, the web server sees no output on STDOUT from the program and so complains that it can't create an HTTP response to send back to the browser - hence the premature end of script headers (which I think is an Apache Web Server error message)