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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing Data Into HTML

Status
Not open for further replies.

Neoport

Programmer
Aug 4, 2000
10
US
Hi,<br><br>I have been programming Perl for the last couple weeks.&nbsp;&nbsp;Getting into the web part of Perl is really exciting.&nbsp;&nbsp;But now I'm stuck.&nbsp;&nbsp;I'm trying to print data from file recursively to the html document and it doesn't work properly.&nbsp;&nbsp;<br><br>Can someone tell me what steps to solve the problem.<br><br>
 
I have open the file and assign the whole file to an array.<br>@A = &lt;HANDLE&gt;;<br>while($Line = shift(@A)) { print $Line; }<br>This will work fine, but I can't print this in hmtl document.&nbsp;&nbsp;When I'm trying to print anything in HTML, I cannot do any manupilations with Perl's syntax.&nbsp;&nbsp;Is there a solution to this............<br><br><br>
 
Hello Neoport,<br>Sounds like we're just getting our feet wet.&nbsp;&nbsp;The code below&nbsp;&nbsp;has several examples of different basic approaches to printing output to a web page.<br><br><i>print &lt;&lt;EndPrint<br>some stuff to print<br>EndPrint</i><br>The word 'EndPrint' can be any normal string.&nbsp;&nbsp;Perl prints everything between the two instances of 'EndPrint'.<br><br><i>print &quot;$line&lt;BR&gt;&quot;;</i><br>Print the line from the file followed by a &lt;BR&gt;.<br><br><br>Note the 'Content-type' line must be exactly like it is here (until we want to change it deliberately).&nbsp;&nbsp;You can see that after the 'Content-type' line, we simply print the top of an HTML page, then open a file and print each line, and then print the closing tags for the page.<br><br><FONT FACE=monospace><br>#!/usr/local/bin/perl -w<br>print &quot;Content-type:&nbsp;&nbsp;text/html\n\n&quot;;<br>print &lt;&lt;EndPrint;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;HTML&gt;&lt;HEAD&gt;&lt;TITLE&gt;Simple CGI Page&lt;/TITLE&gt;&lt;/HEAD&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;BODY&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;P&gt;<br>EndPrint<br><br>$file = './fileList'; <font color=red># change to read something on your system</font><br>open(IPF,&quot;&lt;$file&quot;) or &showError('Failed to open input file');<br>while ($line = &lt;IPF&gt;) { print &quot;$line&lt;BR&gt;&quot;; }<br>close IPF;<br><br>print &lt;&lt;EndPrint;<br>&nbsp;&nbsp;&nbsp;&nbsp;$line to demonstrate that you can print a var inside an EndPrint.<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/P&gt;&lt;/HTML&gt;<br>EndPrint<br><br>sub showError<br>{<br>my $error = $_[0];<br>print &quot;ERROR - $error&lt;BR&gt;\n&quot;;<br>print '&lt;/P&gt;&lt;/HTML&gt;';<br>exit;<br>}<br></font><br><br>'hope this helps.... <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
I took the same approach as you did, however I did it on the file...so everytime the user enters the data, I would add the &lt;br&gt; and whatever that I like next to the data.<br><br><br>Henry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top