Help with formatting output with Text::Table

M

Mothra

Hi All,

I need some help formatting text output using Text table.
Is there a way to increase the space between the columns?
The output from what I have is:

Date Sunset Time
12/01/2003 16:42:32
12/01/2003 16:42:40
12/02/2003 16:42:32

What I would like is:

Date Sunset Time
12/01/2003 16:42:32
12/01/2003 16:42:40
12/02/2003 16:42:32

(I hope the newsreader does not screw this up)
I need to increase the space between the columns.
Also, Is there a way to add an overall title?
like:
Covenant Christian School location
Date Sunset Time
12/01/2003 16:42:32
12/01/2003 16:42:40
12/02/2003 16:42:32
Have the main title ( Coventant Christian school location) the
main center then Date (centered) Sunset Time (centered).

I hope this makes sense.
Thanks

Mothra


#!/app/perl5.8.0/bin/perl
use strict;
use warnings;
use Text::Table;
use DateTime;
use DateTime::Event::Sunrise;

my $dt = DateTime->new( year => 2003,
month => 12,
day => 01,
time_zone => 'America/Los_Angeles',
);
my $dt2 = DateTime->new( year => 2003,
month => 12,
day => 31,
time_zone => 'America/Los_Angeles',
);

my $sunset = DateTime::Event::Sunrise ->sunset(
longitude =>'-117.82399' ,
latitude => '33.80525',
);

my $dt_span = DateTime::Span->new( start =>$dt, end=>$dt2 );
my $set = $sunset->intersection($dt_span);
my $iter = $set->iterator;

my $tb = Text::Table->new(
{ title => 'Date', align_title => 'center' },
{ title => 'Sunset Time', align_title => 'center' }
);

for (1..32) {
my $tmp = $iter->next;
$tb->load(
[ $tmp->mdy('/'), $tmp->hms(':') ]
);

}

print $tb;
 
G

Gunnar Hjalmarsson

Mothra said:
I need some help formatting text output using Text table. Is there
a way to increase the space between the columns? The output from
what I have is:

Date Sunset Time
12/01/2003 16:42:32
12/01/2003 16:42:40
12/02/2003 16:42:32

What I would like is:

Date Sunset Time
12/01/2003 16:42:32
12/01/2003 16:42:40
12/02/2003 16:42:32

How about doing as the documentation for Text::Table suggests? ;-)

my $tb = Text::Table->new(
{ title => 'Date', align_title => 'center' },
{ is_sep => 1, title => ' ' },
{ title => 'Sunset Time', align_title => 'center' }
);
 
K

ko

Mothra said:
Hi All,

I need some help formatting text output using Text table.
Is there a way to increase the space between the columns?
The output from what I have is:

Date Sunset Time
12/01/2003 16:42:32
12/01/2003 16:42:40
12/02/2003 16:42:32

What I would like is:

Date Sunset Time
12/01/2003 16:42:32
12/01/2003 16:42:40
12/02/2003 16:42:32

(I hope the newsreader does not screw this up)
I need to increase the space between the columns.
Also, Is there a way to add an overall title?
like:
Covenant Christian School location
Date Sunset Time
12/01/2003 16:42:32
12/01/2003 16:42:40
12/02/2003 16:42:32
Have the main title ( Coventant Christian school location) the
main center then Date (centered) Sunset Time (centered).

I hope this makes sense.
Thanks

Mothra

[snip code]

There probably is a better way to do this, since the following code
uses two tables to align the 'overall title':

#!/usr/bin/perl -w
use strict;
use Text::Table;

my @data = map [ split ], <DATA>;

my $t1 = Text::Table->new(
{ title => 'Date', align => 'center', align_title => 'center' },
{ is_sep => 1, title => ' ' x 4 }, # change '4' to your needs
{ title => 'Sunset Time', align => 'center',
align_title => 'center' },
);
$t1->load( @data );

my $t2 = Text::Table->new(
{ title => 'Covenant Christian School location',
align => 'center', align_title => 'center',
}
);
$t2->load( map { chomp; [$_] } $t1->table );

print $t2;

__DATA__
12/01/2003 16:42:32
12/01/2003 16:42:40
12/02/2003 16:42:32

HTH - keith
 
M

Mothra

Hi Gunnar,

Gunnar Hjalmarsson said:
Mothra said:
I need some help formatting text output using Text table. Is there
a way to increase the space between the columns? The output from
what I have is:
[snipped]

How about doing as the documentation for Text::Table suggests? ;-)

I guess I missed that :(
my $tb = Text::Table->new(
{ title => 'Date', align_title => 'center' },
{ is_sep => 1, title => ' ' },
{ title => 'Sunset Time', align_title => 'center' }
);
yep! That works great :)
Thanks

Mothra
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top