Data::Table Perl Module
Programming at High Level

[ Download | Cookbook | History | CPAN | Support ]

News

Perl Data::Table Cookbook is available! (ver 1.08, last modified Jan 14, 2014)
[Download Cookbook]
 
The latest Data::Table release is 1.70 (Feb 13, 2014).
We release Data::Table::Excel (0.3) to read/write Excel .xls/.xlsx into/from Data::Table.
 

Example

    #!/usr/bin/perl
    use Data::Table;
    use CGI;
    use DBI;
    $q = new CGI;
    print $q->header;
    $dbh = DBI->connect("DBI:mysql:test", 'test', '');
    $t = Data::Table::fromSQL($dbh,
     "select * from test.aa order by Entry");
    $t->rename('Aminoacid', 'Amino acid');
    $t->rename('Grams', 'Grams per 100g sol.');
    $t->rename('Temp', 'Temp (C)');
    $t->colMap('Amino acid',
     sub { 
     "<a href='http://search.yahoo.com/bin/search?p=$_'>$_</a>"
     });
    print "<b>table::html</b>";
    print $t->html;
    print "<br><b>table::html2</b>";
    print $t->html2;

    table::html
    Entry Amino acid Solvent Grams per 100g sol. Temp (C) Ref_No
    1 Alanine 0.00 0.01 25.00 1
    2 L-aspartate 0.00 0.00 25.00 2
    3 L-glutamate 0.00 0.01 44.93 2
    4 Glycine 0.00 0.00 25.00 1

    table::html2
    Entry 1 2 3 4
    Amino acid Alanine L-aspartate L-glutamate Glycine
    Solvent 0.00 0.00 0.00 0.00
    Grams per 100g sol. 0.01 0.00 0.01 0.00
    Temp (C) 25.00 25.00 44.93 25.00
    Ref_No 1 2 2 1

    New methods: group & pivot (Version 1.41, to be available)
    $t = new Data::Table(
    [
    ['Tom', 'male', 'IT', 65000],
    ['John', 'male', 'IT', 75000],
    ['Peter', 'male', 'HR', 85000],
    ['Mary', 'female', 'HR', 80000],
    ['Nancy', 'female', 'IT', 55000],
    ['Jack', 'male', 'IT', 88000],
    ['Susan', 'female', 'HR', 92000]
    ],
    ['Name', 'Sex', 'Department', 'Salary'], 0);

    sub average {
    my @data = @_;
    my ($sum, $n) = (0, 0);
    foreach $x (@data) {
    next unless $x;
    $sum += $x; $n++;
    }
    return ($n>0)?$sum/$n:undef;
    }

    $t2 = $t->group(["Department","Sex"],["Name", "Salary"],
     [sub {scalar @_}, \&average],
     ["Nof Employee", "Average Salary"]);
    print $t2->html;
    SexDepartmentNof EmployeeAverage Salary
    maleIT376000
    maleHR185000
    femaleHR286000
    femaleIT155000
    $t2 = $t2->pivot("Sex", 0, "Average Salary",["Department"]); print $t2->html;
    Departmentfemalemale
    IT5500076000
    HR8600085000