Forum Moderators: open

Message Too Old, No Replies

Perl and Html

copy paste ??

         

fashezee

11:49 pm on May 25, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a script that will send back a certain HTML page once the user fills out the form. My script is written using Perl, and Perl requires me to put the word "print" at the begining of each line and each line must by put in quotes. Is there easy way of doing this instead of manually?

i.e.
print "Content-Type: text/html\n\n";
print "<html><head><title>Thank You</title></head>\n";
print "<body>Thank You\n";
print "The information has been sent and here is what you submitted:<hr>\n";
print "</body></html>\n";

jeremy goodrich

12:11 am on May 26, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You might want to use an html file, and then swap through some pointers.

At least, that's what I do.
[perl]
print "Content-Type: text/html\n\n";
$var1 = 'stuff';
$var2 = 'otherstuff';
$var3 = 'yetmorestuff';

open(FILE, "template.html") or die "could not open template.html $!";

while(<FILE>){
s/_var1_/$var1/ig;
s/_var2_/$var2/ig;
s/_var3_/$var3/ig;
print;
}
close(FILE);
exit;
[/perl]

the _var1_ _var2_ and _var3_ are pointers in the html file template.html that you are searching and replacing with the contents of the three variables, $var1, $var2, and $var3.

This way you can add a lot of stuff really quickly, and leave your code such that if you change the design of your site, you don't have to modify your code.

I've saved myself a lot of time doing it this way, instead of simply printing the html from within perl.

Of course, you can also use the CGI.pm module for that, but I've always thought of that as overkill (how much perl do you need for CGI anyway?).

Hope that helps.

fashezee

12:32 am on May 26, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code you posted should reside in a HTML file and my form should point to this file?

Don't I need the .pl extension for the code to execute?

widhadh

12:38 am on May 26, 2002 (gmt 0)



The above code goes into a perl file which would end with .pl or .cgi depending on your web server configuration.

The html form should point to that perl script eg:
<form action = "./script.cgi">