[Techtalk] [Perl] cgi.pm - save input in .html file
Michelle Murrain
michelle at murrain.net
Tue Jan 9 18:22:04 UTC 2007
On Jan 9, 2007, at 3:59 AM, Chris Henderson wrote:
> I created a cgi file (test.cgi) which takes user input and shows at
> the bottom of test.cgi. I want the result to be saved to a .html file
> so the other people can view the result. I understand that I need to
> open a file handle and somehow write the input from test.cgi to that
> file handle but I am not too sure how. Here's my code -
Open a file handle like:
open(FILE, "test.html") or print p, "Can't write to test.html";
# It's always a bad thing to just use "die" in cgi scripts
print FILE start_html('Page result');
print FILE h1('Test Results');
blah blah blah
close (FILE);
Basically, use the same type of code for printing to the file that
you use for printing to a page. It will result in valid HTML.
Also, I always use object notation for the cgi.pm like:
my $q = new('CGI');
print $q->p("This is a test");
In this case, you'd then do print FILE $q->p("blah blah");
I find it makes things easier for me, but that's my own personal
preference.
Peace,
Michelle
-------------------
Michelle Murrain
michelle at murrain.net
Blogs: http://www.metacentricities.com
http://www.zenofnptech.org
"One doesn't discover new lands without consenting to lose sight of
the shore for a very long time." -- Andrés Gide
More information about the Techtalk
mailing list