tabularize auto-pager
[hband-tools.git] / tabdata / td-pivot
blob8c01a6ff72c8f7ac4a362e80677608d572f1ff9c
1 #!/usr/bin/env perl
3 =pod
5 =head1 NAME
7 td-pivot - Switch columns for rows in tabular data
9 =head1 SYNOPSIS
11 td-pivot
13 =head1 CAVEAT
15 Must read and buffer the whole STDIN before output any data,
16 so inpractical on large data.
18 =cut
20 no if ($] >= 5.018), 'warnings' => 'experimental::smartmatch';
21 do '/usr/lib/tool/perl5/tabdata/common.pl' or die "$@";
24 @data = ();
25 $max_col = 0;
27 while(not eof STDIN)
29 my @row = read_record(\*STDIN);
31 my $cols = scalar @row - 1;
32 $max_col = $cols if $cols > $max_col;
33 push @data, [@row];
36 for my $cnum (0..$max_col)
38 print join $FS, map {$_->[$cnum]} @data;
39 print $RS;