Using Perl to align text in an HTML page

R

Rob

Hi,

My final objective is to create a Word doc (formatted the way I want
it) that is a collection of names contained in a MySQL database. My
approach has been to output the information to a web page, then copy &
paste it into my Word doc (basically because all the info is getting
inputted by a web page and web pages are easy to deal with...I'm not
married to this approach).

I have a situation where I want to print:

Lastname Firstname
Firstname2

Where the names are names of people in a family. These names reside in
my database. I want them aligned nicely, as I've shown. I repeat this
process for many families. I'm using a Perl script to go get the info
from the database and send it to a web page. The problem I'm having is
the two firstnames don't align nicely. I can't simply place Firstname2
over a certain number of spaces since Lastname varies in length,
especially since it is in bold (and firstnames are not).

I don't want to use a table since if I paste that into a Word doc the
table shows up in Word, which I don't want.

I tried using:

<SCRIPT LANGUAGE='Javascript'>
document.write("<XMP>")
document.write("100 Meter\t400 Meter\t1500 Meter\r")
document.write("110 Hurdles\tHigh Jump\tlong Jump\r")
document.write("Javelin\t\tPole Vault\tShot Put\r")
document.write("Discus")
document.write("</XMP>")
</SCRIPT>

Which I found on the web. In a "normal" web page it works great. I
added it to my Perl script:

#!C:/Perl/bin/Perl.exe

print qq(
<html>
<SCRIPT LANGUAGE='Javascript'>
document.write("<PRE>")
document.write("100 Meter\t400 Meter\t1500 Meter\r")
document.write("110 Hurdles\tHigh Jump\tlong Jump\r")
document.write("Javelin\t\tPole Vault\tShot Put\r")
document.write("Discus")
document.write("</PRE>")
</SCRIPT>
</html>);
exit;

and it seems like the web page simply ignores it - it doesn't print
*anything*, let alone the tabs.

Any thoughts?
Thanks! Rob.
 
A

A. Sinan Unur

Which I found on the web. In a "normal" web page it works great. I
added it to my Perl script:

#!C:/Perl/bin/Perl.exe

print qq(
<html>
<SCRIPT LANGUAGE='Javascript'>
document.write("<PRE>")
document.write("100 Meter\t400 Meter\t1500 Meter\r")
document.write("110 Hurdles\tHigh Jump\tlong Jump\r")
document.write("Javelin\t\tPole Vault\tShot Put\r")
document.write("Discus")
document.write("</PRE>")
</SCRIPT>
</html>);
exit;

and it seems like the web page simply ignores it - it doesn't print
*anything*, let alone the tabs.

Any thoughts?


Yes. Learn HTML, Javascript and Perl individually first, before you try to
intermingle them like this to create a Frankenstein.

Sinan.
 
T

TB

Hmm...in my experience, tabs and HTML don't really get along. I think
your problem could be solved at least two ways. The simplest would be
to insert a <pre> tag to align things in a courier type font (not
pretty). Secondly, write you a <table> tag out. Next maybe write a
header row like this:

<th>Last Name</th>
<th>First Name</th>
<th>First Name 2</th>

....then as you loop through the rows in the database, start with
<tr>
....loop through each column in the table..
<td>lastname</td>
<td>firstname</td>
<td>firstname2</td>
....close out the html table row,
</tr>
....continue looping through table until all rows are processed.
Then close the table: </table>
Not elegant, but it might get you through.

HTH -TB
 
C

ChrisO

TB said:
Hmm...in my experience, tabs and HTML don't really get along. I think
your problem could be solved at least two ways. The simplest would be
to insert a <pre> tag to align things in a courier type font (not
pretty). Secondly, write you a <table> tag out. Next maybe write a
header row like this:

<th>Last Name</th>
<th>First Name</th>
<th>First Name 2</th>

...then as you loop through the rows in the database, start with
<tr>
...loop through each column in the table..
<td>lastname</td>
<td>firstname</td>
<td>firstname2</td>
...close out the html table row,
</tr>
...continue looping through table until all rows are processed.
Then close the table: </table>
Not elegant, but it might get you through.

HTH -TB

The OP said *no tables*. Your entry into the contest is disqualified.

-ceo
 
C

ChrisO

Rob said:
Hi,

My final objective is to create a Word doc (formatted the way I want
it) that is a collection of names contained in a MySQL database. My
approach has been to output the information to a web page, then copy &
paste it into my Word doc (basically because all the info is getting
inputted by a web page and web pages are easy to deal with...I'm not
married to this approach).

I have a situation where I want to print:

Lastname Firstname
Firstname2

Where the names are names of people in a family. These names reside in
my database. I want them aligned nicely, as I've shown. I repeat this
process for many families. I'm using a Perl script to go get the info
from the database and send it to a web page. The problem I'm having is
the two firstnames don't align nicely. I can't simply place Firstname2
over a certain number of spaces since Lastname varies in length,
especially since it is in bold (and firstnames are not).

I don't want to use a table since if I paste that into a Word doc the
table shows up in Word, which I don't want.

I tried using:

<SCRIPT LANGUAGE='Javascript'>
document.write("<XMP>")
document.write("100 Meter\t400 Meter\t1500 Meter\r")
document.write("110 Hurdles\tHigh Jump\tlong Jump\r")
document.write("Javelin\t\tPole Vault\tShot Put\r")
document.write("Discus")
document.write("</XMP>")
</SCRIPT>

Which I found on the web. In a "normal" web page it works great. I
added it to my Perl script:

#!C:/Perl/bin/Perl.exe

print qq(
<html>
<SCRIPT LANGUAGE='Javascript'>
document.write("<PRE>")
document.write("100 Meter\t400 Meter\t1500 Meter\r")
document.write("110 Hurdles\tHigh Jump\tlong Jump\r")
document.write("Javelin\t\tPole Vault\tShot Put\r")
document.write("Discus")
document.write("</PRE>")
</SCRIPT>
</html>);
exit;

and it seems like the web page simply ignores it - it doesn't print
*anything*, let alone the tabs.

Any thoughts?

Your Perl worked for me under AS Perl v5.8.3 and Cygwin Perl alike on
Windows XP...? You JavaScript however needs to end with semicolons on
each line (for the JS you output). Also, your \t tab characters aren't
going to do what you want them to do in this output. You need \\t so
that it shows up as \t in the JavaScript output.

If you are going to continue pursuing a MySQL -> HTML -> Word
"conversion", and you don't want HTML tables, you may want to try using
a CSS style sheet with absolute position for "columns". I have NO IDEA
how that will carry over into Word when you cut and paste. It's just a
thought I had. Trying to get stuff to align in HTML without using
tables is problematic at best, but if you stretch, it can be done.

Personally, I would probably consider a Win32::OLE approach and take my
data directly from MySQL and place it into a Word document being created
with Win32::OLE directly. I don't think it's THAT hard.

-ceo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top