Return-Path: Mailing-List: contact modperl-help@apache.org; run by ezmlm Delivered-To: mailing list modperl@apache.org Received: (qmail 64439 invoked from network); 5 Jul 2000 13:25:02 -0000 Received: from corpex.laserlink.net (208.216.91.202) by locus.apache.org with SMTP; 5 Jul 2000 13:25:02 -0000 Received: by corpex.laserlink.net with Internet Mail Service (5.5.2650.21) id ; Wed, 5 Jul 2000 09:29:30 -0400 Message-ID: From: Geoffrey Young To: "'rob@artistdirect.com'" , modperl@apache.org Subject: RE: can't properly append to file from mod_perl script Date: Wed, 5 Jul 2000 09:29:26 -0400 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: text/plain; charset="iso-8859-1" X-Spam-Rating: locus.apache.org 1.6.2 0/1000/N Are you setting PerlWarn On and checking for errors? I get these when compiling your script under RegistryLoader: Variable "$results_file" will not stay shared at /usr/local/apache/perl-bin/test.cgi line 29. Variable "$entry" will not stay shared at /usr/local/apache/perl-bin/test.cgi line 31. Variable "$display_file" will not stay shared at /usr/local/apache/perl-bin/test.cgi line 38. Useless use of concatenation in void context at /usr/local/apache/perl-bin/test.cgi line 56. see http://perl.apache.org/guide/perl.html#my_Scoped_Variable_in_Nested_S the mod_perl guide is full of lots of goodies that are worth reading... HTH --Geoff > -----Original Message----- > From: Rob Egan [mailto:rob@artistdirect.com] > Sent: Friday, June 30, 2000 8:01 PM > To: modperl@apache.org > Subject: RE: can't properly append to file from mod_perl script > > > Hi, > > I sent an earlier post with a script that was appending > garbage along with > user email addresses that were submitted through a form. > After seeing all > the suggestions about improvement, I went ahead and rewrote > the script from > scratch (it's much shorter now!). My version actually > prevents garbage from > being placed into the output file, but it still has a > problem. If I open up > two browsers on separate machines, go to the page containing > the form, and > simultaneously submit addresses from both machines, after maybe 8 or 9 > entries the output becomes incorrect. For example, if I enter > the following > e-mail addresses one at a time from the form: > > user1@test.com > user2@test.com > user3@test.com > user4@test.com > user5@test.com > > Then I view the output file and see this output: > > user1@test.com > user2@test.com > user3@test.com > user1@test.com > user1@test.com > > It's as though the parameters I'm pulling from the form get > stuck somewhere, > but I can't figure out where. I tried autoflushing buffers > for both STDOUT > and the output channel I use to write the output (called > RESULTS in the > script), but that doesn't help. Some of you guys had > mentioned writing some > cleanup code after I close my file, but I don't quite > understand what I need > to clean up (sorry, I'm kind of new at this). Any ideas? (the > code is below) > > -Rob > > --------begin script text---- > #!/usr/local/bin/perl -w > > # call strict, CGI, and Fcntl modules > use strict; > use CGI; > use Fcntl qw(:flock); > use FileHandle; > > # autoflush buffers > $| = 1; > > # Variable definitions > my $results_file = "./beastie.results.csv"; > my $display_file = "./email_thankyou.html"; > my $entry; > > ####----Sub routine definitions----Don't change anything > below here----#### > > # General error routine (takes 3 string arguments, displays > results in HTML) > sub bail { > my ($status, $keyword, $message) = "@_"; > print h1("$status $keyword"), p($message), end_html(); > die $message; > } > > # Open results file, lock it, write entry, close/unlock it. > sub write_entry { > RESULTS->autoflush(1); > open(RESULTS, ">>$results_file") || bail(500, "Results > Error", "$!"); > flock(RESULTS, LOCK_EX); > print RESULTS $entry; > close(RESULTS); > } > > # Display thank you page with link back to main site. > sub say_thanks { > print CGI::header(); > open(DISPLAYFILE, "<$display_file") || bail(500, "Error", "$!"); > while() { > print; > } > close(DISPLAYFILE); > } > > ####----Begin main program----#### > > # Create CGI object, and gather email addresses into array > my $query = CGI->new(); > my $address = $query->param('email'); > > # Format URL encoded email address into ascii, append date > stamp to it. > $address =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack("C", hex($1))/eg; > $entry = "$address, " . localtime() . "\n"; > > # Write the email and timestamp to results file, display > thank you page, > exit. > write_entry(); > say_thanks(); > exit(0); > > ####----End of script----#### >