NAME

Data::Tabulator - Create a table (two-dimensional array) from a list (one-dimensional array)

VERSION

Version 0.03

SYNOPSIS

my $table = Data::Tabulator->new([ 'a' .. 'z' ], rows => 6);
my $rows = $table->rows;
# Returns a the following two-dimensional array:
# [ 
#  [ qw/ a b c d e / ],
#  [ qw/ f g h i j / ],
#  [ qw/ k l m n o / ],
#  [ qw/ p q r s t / ],
#  [ qw/ u v w x y / ],
#  [ qw/ z/ ],
# ]

my $columns = $table->columns;
# Returns a the following two-dimensional array:
# [ 
#  [ qw/ a f k p u z / ],
#  [ qw/ b g l q v / ],
#  [ qw/ c h m r w / ],
#  [ qw/ d i n s x / ],
#  [ qw/ e j o t y / ],
# ]

DESCRIPTION

Data::Tabulator is a simple and straightforward module for generating a table from an array. It can properly handle data that is in either row- or column-major order.

EXPORTS

rows( <array>, ... )
rows( data => <array>, ... )

Extracts and returns the rows of the array.

A shortcut to ->new, see Data::Tabulator->new for parameter specification and more information.

columns( <array>, ... )
columns( data => <array>, ... )

Extracts and returns the columns of the array.

A shortcut to ->new, see Data::Tabulator->new for parameter specification and more information.

METHODS

Data::Tabulator->new( <array>, ... )
Data::Tabulator->new( data => <array>, ... )

The first argument to new may be an array (a list reference). Alternatively, you can pass in the array via the "data" parameter.

The following parameters are also accepted:

    data => The array (list reference) to turn into a table.

    rows => The number of rows the table should have.

    columns => The number of columns the table should have.

    pad => A true/false indicator on whether to pad if the array is not long enough. The default is not to pad.

    padding => The padding data to use if the array is not long enough (not a full M x N table). The default is undef.

    row_major => A true value indicates that the array data is in row-major order. This is the default.

    column_major => A true value indicates that the array data is in column-major order.

Note: passing in "padding" and not specifying the "pad" option will automatically turn "pad" on.

$table->data
$table->data( <array> )

Return a reference to the underlying array of the table.

Alternatively, make $table use the specified <array>.

When setting $table->data, make sure you're passing in a list reference.

$table->width

Return the width of the table (the number of columns).

$table->height

Return the height of the table (the number of rows).

$table->dimensions
$table->geometry

Return the width and height of the table.

In scalar context, this will return a two-element array.

my ($width, $height) = $table->geometry;
my $geometry = $table->geometry;
$width = $geometry->[0];
$height = $geometry->[1];
$table->pad( <indicator> )

Toggle padding on/off.

$table->padding( <padding> )

Set the padding data to use.

$table->row_major

Return true if the data for $table is in row-major order.

$table->column_major

Return true if the data for $table is in column-major order.

$table->rows

Return an array of rows in the table.

$table->rows( <count> )

Set the number of rows in the table to <count>. This is equivalent to passing in row_count to the new method. As a side effect, this will change the number of columns in table.

Does not return anything.

$table->columns

Return an array of columns in the table.

$table->columns( <count> )

Set the number of columns in the table to <count>. This is equivalent to passing in column_count to the new method. As a side effect, this will change the number of rows in table.

Does not return anything.

$table->row( <i> )

Return row <i>

<i> should be a number from 0 to $tables->rows - 1

$table->column( <j> )

Return column <j>

<j> should be a number from 0 to $tables->columns - 1

$table->as_string( [<row-separator>], [<column-separator>] )

Return the table as a simple string.

By default, rows are separated by "\n" and columns are separated by " ".

SEE ALSO

Data::Tabulate, Data::Table

AUTHOR

Robert Krimen, <rkrimen at cpan.org>

BUGS

Please report any bugs or feature requests to bug-data-tabulate at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data-Tabulator. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Data::Tabulator

You can also look for information at:

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

Copyright 2007 Robert Krimen, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.