Data::Table Perl Module

Programming at High Level

[ Download@CPAN | Cookbook ]

News

Perl Data::Table Cookbook is available! (ver 1.10, last modified Feb 11, 2020)

[Download Cookbook]

The latest Data::Table release is 1.78 (Feb 11, 2020).

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;

$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;

$t2 = $t2->pivot("Sex", 0, "Average Salary",["Department"]); print $t2->html; 

Copyright © easydatabase at gmail dot com