Reputation: 845
I have a text file saved in the server side. I have to read the file and display its content to the browser using perl CGI. The file has several paragraphs, newline and tab characters. I want to preserve those formatting. Currently the contents of the file is displayed, but it is all jumbled up as a single continuous paragraph.
print "<table border='1'>\n";
print "<tr>\n";
print "<td><b>Whole Report</b></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td>$entireReport</td>\n";
print "</tr>\n";
print "</table>\n";
In the above code, I am reading the entire content of the file into the variable $entireReport.
Thanks
Upvotes: 0
Views: 1033
Reputation: 4491
wrap the code in a <PRE></PRE> tag. Say you have the contents in $fileContents then use:
print "<td><pre>", CGI::escapeHTML($fileContents), "</pre></td>\n";
This will keep the formatting in the file verbatim.
--dmg
Upvotes: 1