CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
writing to files

 



sadielane
stranger

Oct 24, 2001, 10:58 AM

Post #1 of 3 (604 views)
writing to files Can't Post

help! i am trying to write the contents of an html form to a file with a cgi script, but for some reason when i execute the script nothing is happening. i have tried perl -cw command and the syntax is fine-- does anyone have any idea why this wouldn't work? here is the script, if that helps:

#!/usr/bin/perl
#
#######

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

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/\n/ /g; # replace newlines with spaces
$value =~ s/\r//g; # remove hard returns
$value =~ s/\cM//g; # delete ^M's
$FORM{$name} = $value;
}

open (LOGFILE,">>/gagehouse/cgi-bin/data_files/jha.log") or dienice("Cannot open jha.log for writing: $!");

# this locks the file so no other CGI can write to it at the same time
flock(LOGFILE,2);

# reset the file pointer to the end of the file, in case
# someone wrote to it while we waited for the lock
seek(LOGFILE,0,2);

$newline=join('|',@value);

print LOGFILE ("$newline\n");
close LOGFILE;

#this next line won't let the 'stationnumber' field be left blank
if ($FORM{'stationnumber'} eq "") {
dienice("Please enter a station number into the JHA form.");
} else
{print "<BODY BGCOLOR=\"#cccc99\" text=\"#003300\"><BR><BR><H1 align=center>Thank you. The Job Hazard Analysis for this site has been updated.</H1>";
}

#####
#subroutines
#
#dienice subroutine, for handling errors
sub dienice {
my($errmsg) = @_;
print "<h2>Error</H2>\n";
print "$errmsg<p>\n";
print "</body></html>\n";
exit;
}




vallely
Novice

Oct 24, 2001, 1:10 PM

Post #2 of 3 (601 views)
Re: writing to files [In reply to] Can't Post

I only see @value once.

on this line ---
$newline=join('|',@value);

If @value has no values to join then $newline eq ""

Do you want to add your form data to @value like this?

@value = ($FORM{'stationnumber'} ", "$FORM{'moreformdata'}", "$FORM{'evenmoreformdata'}");




















sadielane
stranger

Oct 24, 2001, 3:16 PM

Post #3 of 3 (595 views)
Re: writing to files [In reply to] Can't Post

thank you so much! an obvious mistake, but i think i had just been thinking about it way too much. thanks for pointing it out for me...



 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives