I am using Perl to read data from a file into an array then using HTML::Template to display the data in a HTML page. All I am doing is reading the data into the array line by line and outputting it.
Or I was until I noticed that the data in the middle section of the file was misaligned on the web page. I then wrote some Perl code to pad the first part of the line and then add the second column back in. Example on the web page:
T - Online Transmit Done R - Online Request Allowed
E - Extracted batch M - Multiple transmission
P - Transmission in Progress U - Batch Unextractable
N - Batch Nontransmittable B - BSC
If I copy and paste the data from the web page I get this perfectly aligned:
T - Online Transmit Done R - Online Request Allowed
E - Extracted batch M - Multiple transmission
P - Transmission in Progress U - Batch Unextractable
N - Batch Nontransmittable B - BSC
Where am I going wrong? The data is showing as correctly padded but not inside a table on an HTML page. Here is the HTML I am using, nothing fancy:
<TABLE BORDER=1 ALIGN="center">
<TR>
<TD ALIGN="center"><B>DATA</B></TD>
</TR>
<TMPL_LOOP NAME="THIS_LOOP">
<TR>
<TD ALIGN="left"><TMPL_VAR NAME="DATA"></TD>
</TR>
</TMPL_LOOP>
</TABLE>
You could use a monospaced font, like Courier, for your table data. Your columns aren’t lining up because the font you are using has different widths for different letters.
But positioning elements with spaces is not a good idea. It’d be worthwhile to rethink your layout / logic and use tables as they were intended to be used.