The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Docbook::Table -- create Docbook tables from Perl data structures


    use Docbook::Table;
    my $t = Docbook::Table->new();
    $t->title("Pet names");
    $t->headings("Pet type", "Pet name");

    my %pets = (
        dog     => "Rover",
        cat     => "Garfield",
        bird    => "Tweetie"




This module generates Docbook SGML/XML tables from Perl data structures. Its main purpose is to simplify automatic document generation.

Starting your table

    use Docbook::Table;
    my $t = Docbook::Table->new();

Specifying the title

Docbook tables must have a title. You can set the title by passing a string to the title() method.

    $t->title("This is the title");

Specifying the headings

Simply pass a list of headings to the headings() method.


Note that the number of columns (a required attribute of the tgroup element) is generated by counting the number of elements in the list passed to headings().

Specifying the body

Accepted data types for the body of the table are:

Simple hash

Used to generate a simple 2-column table.

List of lists

Used to generate multi-column tables.

Hash of lists

Used to generate multi-column tables.

Hash of hashes and other structures

Not supported (yet).

All data structures for the body should be passed by reference to the body() method.


If you pass it the wrong sort of thing, it will emit a warning and return undef.


By default, hashes are sorted asciibetically by key, and lists are left in their original order. If you wish to specify a different sort order, pass a subroutine reference to the sort() method.

    $t->sort( sub { $b cmp $a } );

If you pass it anything other than a subroutine reference, it will emit a warning and return undef.

Generating the table

The generate() method actually generates the table for you and returns it as a string. It will emit warnings and return undef if you haven't specified a title, headings and a body.


Kirrily Robert <>


Docbook::Table (c) 2001 Kirrily Robert <> This software is distributed under the same licenses as Perl itself.