See bottom for my response...

-----Original Message-----
From: dan [mailto:dan@;abovenet.org]
Sent: Monday, October 21, 2002 5:42 PM
To: [EMAIL PROTECTED]
Subject: Tables


ok, this probably has an easy answer, but yet i can't think of it. i want to
create a "table", not a table in html, otherwise this would be so easy, but
it's not. the idea is, i have variable length data, and i want to be able to
create a table out of it, if i give you a sample, and show how i'd want perl
to output it, any ideas?

sample data:
1 Erazor 100 0 0
2 AnGeL` 500 0 0
4 ^ML^ 100 0 0
5 Joe 100 0 1
6 Liquid_Snake_911 100 0 0
121 Psycho 100 0 0

and i'd want the data to be outputted in this format (it'll be displayed
using fixed width text):

--------------------------------------------------
| ID  | Nickname         | ULEVEL | SLEVEL | AOP |
|-----|------------------|--------|--------|-----|
| 1   | Erazor           |  100   |   0    |  0  |
| 2   | AnGeL`           |  500   |   0    |  0  |
| 4   | ^ML^             |  100   |   0    |  0  |
| 5   | Joe              |  100   |   0    |  1  |
| 6   | Liquid_Snake_911 |  100   |   0    |  0  |
| 121 | Psycho           |  100   |   0    |  0  |
--------------------------------------------------

but for example, if "Liquid_Snake_911" wasn't there, the table would look
like:

------------------------------------------
| ID  | Nickname | ULEVEL | SLEVEL | AOP |
|-----|----------|--------|--------|-----|
| 1   | Erazor   |  100   |   0    |  0  |
| 2   | AnGeL`   |  500   |   0    |  0  |
| 4   | ^ML^     |  100   |   0    |  0  |
| 5   | Joe      |  100   |   0    |  1  |
| 121 | Psycho   |  100   |   0    |  0  |
------------------------------------------

so the column is either (length of the title + 2) or
(length of largest record + 2).

any clues on how this may be acheived?

ta

dan

-----End Original Message-----
It would take me about 30 minutes to code this up for you, but I don't have
the time, and you wouldn't learn anything.  I think you have an idea of what
you are looking for.  Some documentation that might help:
perldoc perlop (look for "Binary "x" is the repetition operator")
perldoc -f length

And here's some pseudocode of the algorithm I'd use:
Set up a variable for each column with the length of the title
Scroll through each record comparing the length of the column against the
variable for that column, if the record is longer, change the variable's
value.
[I would do the first and last line like the third, but you should be able
to figure out how to use the x to print just ----s for those lines]
Print "|" followed by "-" x (length of the longest record in the first field
+ 2), followed by "|", followed by... and eventually "|\n"
Print "| ",  followed by the first column title, followed by " " x (length
of biggest string in col1-length of col1 title), followed by " | ", followed
by... and eventually "|\n"
....

Code something up, see if it works, if not play with it for awhile.  If you
get stuck, email the list and send us your code and what you've tried and
what still isn't working, and we'll coach you on it.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to