Dan wrote:

> 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

have you try format,$~ and write? something like:

#!/usr/bin/perl -w
use strict;

my @array=(1,'my nick name',2,3,4);

$~ = 'TABLE';
write;

format TABLE_TOP =
---------------------------------------------------------
|ID      |Nickname                |ULEVEL  |SLEVEL  |AOP
|--------|------------------------|--------|--------|----
.

format TABLE =
|@<<<<<  |@<<<<<<<<<<<<<<<<<<<<<< |@<<<<<< |@<<<<<< |@<<<
$array[0], $array[1], $array[2], $array[3], $array[4]
.

__END__

just to give you an idea. if you need to calculate the longest string from 
your Nickname column and then use it as the longest format spaces, you can 
generate the whole format and then eval{} it.

perldoc perlform

has some good doc.

david

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

Reply via email to