Modify An HTML using Perl

I want to ask about how to modify a html using CGI script
(PERL).
I use this to create a CGI Script that can modify name, address, and the comment from a guestbook html file?
How we can load the name, address, comment to our script and
we modify it?
LVL 1
ichenAsked:
Who is Participating?
 
zhongbingConnect With a Mentor Commented:
if i got all your idea then:
1. write a html with a form with the fields you need: name, address, and comment all anything else. the form's action should be the name of your perl excutable file.
2. the perl script get all the parameter, then instead of modify a html, if should totally wirte a new html file to stdout. it means the perl script create a new html and send it to stdout, the user's brower will get the html.

3 the html example (which have a filed name and message):

<head>
<title> post a message </title>
</head>
<body>
<form method="get"  action="http://sac.uky.edu/cgi-bin/cgiwrap/~jcao0/zh.pl">
<P><input type="text" name="name" size="20">
<P> message: <textarea name="message" cols=30 rows=4></textarea>
<P>
<input type="submit" value="submit">
<input type="reset" value="reset">
<form>
</html>
4 perl cgi example(it get the name and message value then wirte it to new html):
#! /usr/bin/perl
$|=1;
print "Content-type:text/html\n\n";
#print "test perl\n";
 
$buffer=$ENV{'QUERY_STRING'};
 
print"$buffer";
 
@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;
        $form{$name}=$value;
}
print"<title> message board </title>";
print"<h1> message board </h1>";
print"<p> name : $form{'name'}";
print"<p> message : $form{'message'}";
0
 
ichenAuthor Commented:
Can I use the perl script  to modify the name, address and comment?
0
 
ichenAuthor Commented:
Can I use the perl script  to modify the name, address and comment?
0
 
mazaresCommented:
I use a much simpler method for this kind of situation. I have the "shell" of the html document already present -- in his case, a guestbook form. I place "flags" such as <!put_id_here> in the html document. Then, my script opens the html file, reads it in as STDIN, outputting it a line at a time. If the script encounters the <!flag>, it then outputs the unique information (in html format) required by the particular flag's location in the document. Thus, the resulting html document is customized according to the user, the user's request, or whatever.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.