Help with formatting output with Text::Table

Discussion in 'Perl Misc' started by Mothra, Dec 8, 2003.

  1. Mothra

    Mothra Guest

    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;
     
    Mothra, Dec 8, 2003
    #1
    1. Advertising

  2. 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
     
    Gunnar Hjalmarsson, Dec 8, 2003
    #2
    1. Advertising

  3. Mothra

    ko Guest

    "Mothra" <> wrote in message news:<>...
    > 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
     
    ko, Dec 9, 2003
    #3
  4. Mothra

    Mothra Guest

    Hi Gunnar,

    "Gunnar Hjalmarsson" <> wrote in message
    news:br30ol$257vkv$-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
     
    Mothra, Dec 9, 2003
    #4
  5. Mothra

    Mothra Guest

    Hi Keith,

    "ko" <> wrote in message
    news:...
    > "Mothra" <> wrote in message

    news:<>...
    > > 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
     
    Mothra, Dec 9, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lemmchen
    Replies:
    4
    Views:
    376
    lemmchen
    Oct 13, 2005
  2. rashmi

    formatting output in the form of table

    rashmi, Jun 21, 2005, in forum: C Programming
    Replies:
    1
    Views:
    281
    Rajan
    Jun 21, 2005
  3. Glen
    Replies:
    6
    Views:
    1,207
    Steve Holden
    Apr 24, 2007
  4. Mothra
    Replies:
    10
    Views:
    488
    Anno Siegel
    Mar 11, 2005
  5. Joseph L. Casale

    Formatting text in a table with reportlab

    Joseph L. Casale, Dec 12, 2013, in forum: Python
    Replies:
    0
    Views:
    106
    Joseph L. Casale
    Dec 12, 2013
Loading...

Share This Page