Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating a html page 1

Status
Not open for further replies.

Myqns

Programmer
Jul 28, 2004
23
GB
Hello all,

I am quite confused about how to create a simple html page with a table from within a perl script. I saw the HTML and HTTP and LWP modules and I am quiet confused. Any one has any simple example I can look at?

Thanks
 
Here is something very very very basic and rubbish but I've made it as plain as possible.

#!/usr/bin/perl

# assumes you load @row with some comma delimited data
# such as
@row = ("1,2,3,4,5", "a,b,c,d,e");

print "<HTML><BODY>";
print "<TABLE>";
foreach (@row) {
my @bits = split (/,/, $_);
print "<TR>";
foreach (@bits) {
print "<TD>$_</TD>";
}
print "</TR>";
}
print "</TABLE>";
print "</BODY></HTML>";


 
You'll also need to print the header, especially if dealing with Apache as a webserver

Code:
print "Content-Type: text/html\n\n";
put that in before printing the <HTML> block

HTH
--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
DOH! Yes, dont forget the header or else it'll not be happy. Thanks PaulTEG, forgot that little bit.

The prog will work but it wont be pretty, good chance to put in some CSS and stuff though!
 
Thanks for you replies.

I tried the following code
Code:
while (($file, $present) = each(%filenonexistshash)) {
	print "File $file $present\n";
print OUTPUT <<END_of_Next;
	<HTML>
    		<HEAD>
    		<TITLE>Input File Status</TITLE>
    		</HEAD>
    		<BODY> 
			<TABLE BORDER="1" BORDERCOLOR="red">	
			<TR>                                         
			<TD>$file</TD>	
                        <TD>$present</TD>		
			</TR>	
			</TABLE>
    		</BODY>	
END_of_Next
}


I am getting a table for each of entry in @lines. But, I want a single table.
 
Code:
print "Content-Type: text/html\n\n";
print "<html><head><title>whatevertitle</title></head>\n";
print "<body><table border=1 cellspacing=0 cellpadding=0>";
foreach  (@lines) {
  print "<tr><td>$_</td><td>$_\n";
}
print "</table></body></html>\n"

dunno anything about your hash so I'm using the array you mentioned
HTH
--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
print OUTPUT "
<HTML>
<HEAD>
<TITLE>Input File Status</TITLE>
</HEAD>
<BODY>
";
print OUTPUT "<TABLE BORDER=\"1\" BORDERCOLOR=\"red\">";

while (($file, $present) = each(%filenonexistshash)) {
print "File $file $present\n";

print OUTPUT <<END_of_Next;
<TR>
<TD>$file</TD>
<TD>$present</TD>
</TR>
END_of_Next
}

print "</TABLE></BODY></HTML>";
 
Ooops, missed a bit again:

print OUTPUT "Content-Type: text/html\n\n";
print OUTPUT "<HTML><HEAD><TITLE>Input File Status</TITLE></HEAD><BODY>";
print OUTPUT "<TABLE BORDER=\"1\" BORDERCOLOR=\"red\">";

while (($file, $present) = each(%filenonexistshash)) {
print "File $file $present\n";

print OUTPUT <<END_of_Next;
<TR>
<TD>$file</TD><TD>$present</TD>
</TR>
END_of_Next
}

print OUTPUT "</TABLE></BODY></HTML>";
 
Thanks all for your valuable posts.

I works now!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top