Data::Pivoter - Perl extension for pivot / cross tabulation of data


$pivoter = Table::Pivoter->new(col=> <col>, row=> <row>, data=> <data>, group=> <group>, function=> <function>, numeric => <boolean>, donotvalidate=> <boolean>, test=><boolean>);

$pivotedtableref = $pivoter->pivot(\@rawtable) if $pivoter->ok;


A pivot object is created using new. Various parameters may be specified to alter how the table is pivoted. The actual pivot of a table is perfomed using the method pivot.



Table::Pivoter->new(col=><col>, row=><row>, data=><data>, group=><group>, function=><function>, numeric=><boolean>, donotvalidate=><boolean>, test=>boolean);

Creates a new pivoter object where <col> is the column containing data going to be the column headings, <row> is the column going to row headings and <data> is the data column. <group> is a column used for higher level grouping, i.e. splitting the data into different tables.

{numerical} is used to flag that the data are numerical so that the correct sorting function is being used. {function} is a function to compile the data set for each row/col combination (Still not implemented) If no function is given, the last value for each data point is returned.

The inputdata to new are validated to check that row,col, and data are defined and that row and col differs. If this behaviour for some reason not is wanted, donotvalidate can be set to a true value. The property test may be set to avoid output from the validation (esp for the internal testing). To check for a well- defined pivoter object, call the method ok.

Planned features (except for implementing the compilation function) includes to add customizable sorting functions for rows and columns.


@pivotedtable = $pivoter->pivot (@rawtable);

The pivoter method actually performs the pivot with the parameters given in new and returns the pivoted table.


The method may be called to see if the pivoter object is well-defined. If donotvalidate is set, then this method will always return true.

New algorithms

A possible enhancement is to use two different types of functions for compilation, one which needs all the data avaliable to perform the calculation, another that can can be applied to the data before all the datapoints are known, (e.g. to return the max value from the data set) to avoid going through the data set twice when possible

System variables

The variable PIVOTER_DEBUG may be set to get debugging output. A higher numerical value gives more output.


This module is distributed under the artistic licence, i.e. the same licence at Perl itself.


Morten A.K. Sickel,