Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Help with formatting output with Text::Table

Reply
Thread Tools

Help with formatting output with Text::Table

 
 
Mothra
Guest
Posts: n/a
 
      12-08-2003
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;


 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      12-08-2003
Mothra wrote:
> 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' }
);

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

 
Reply With Quote
 
 
 
 
ko
Guest
Posts: n/a
 
      12-09-2003
"Mothra" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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
 
Reply With Quote
 
Mothra
Guest
Posts: n/a
 
      12-09-2003
Hi Gunnar,

"Gunnar Hjalmarsson" <(E-Mail Removed)> wrote in message
news:br30ol$257vkv$(E-Mail Removed)-berlin.de...
> Mothra wrote:
> > 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



 
Reply With Quote
 
Mothra
Guest
Posts: n/a
 
      12-09-2003
Hi Keith,

"ko" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> "Mothra" <(E-Mail Removed)> wrote in message

news:<(E-Mail Removed)>...
> > 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:


[more snippage]

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


This works great
Thanks !

Mothra



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Output file formatting/loop problems -- HELP? Maggie Python 5 09-08-2009 06:22 PM
Formatting output fron Helper Function in Template? Syntax? D. Shane Fowlkes ASP .Net 1 05-19-2005 06:40 PM
Formatting Repeater oontrol output =?Utf-8?B?UGl0Y2Fpcm5pYQ==?= ASP .Net 1 02-17-2005 04:04 PM
help with formatting output mark C++ 1 06-15-2004 10:33 PM
Need formatting options menu for formatting hard drive Mark T. Computer Support 3 11-24-2003 11:50 PM



Advertisments