]> git.donarmstrong.com Git - bin.git/blob - pivot_table
add git-hogs command
[bin.git] / pivot_table
1 #! /usr/bin/perl
2 # , and is released
3 # under the terms of the GPL version 2, or any later version, at your
4 # option. See the file README and COPYING for more information.
5 # Copyright 2009 by Don Armstrong <don@donarmstrong.com>.
6 # $Id: perl_script 1432 2009-04-21 02:42:41Z don $
7
8
9 use warnings;
10 use strict;
11
12 use Getopt::Long;
13 use Pod::Usage;
14
15 =head1 NAME
16
17  - 
18
19 =head1 SYNOPSIS
20
21  [options]
22
23  Options:
24   --debug, -d debugging level (Default 0)
25   --help, -h display this help
26   --man, -m display manual
27
28 =head1 OPTIONS
29
30 =over
31
32 =item B<--debug, -d>
33
34 Debug verbosity. (Default 0)
35
36 =item B<--help, -h>
37
38 Display brief usage information.
39
40 =item B<--man, -m>
41
42 Display this manual.
43
44 =back
45
46 =head1 EXAMPLES
47
48
49 =cut
50
51
52 use vars qw($DEBUG);
53
54 my %options = (debug           => 0,
55                help            => 0,
56                man             => 0,
57                );
58
59 GetOptions(\%options,
60            'debug|d+','help|h|?','man|m');
61
62 pod2usage() if $options{help};
63 pod2usage({verbose=>2}) if $options{man};
64
65 $DEBUG = $options{debug};
66
67 my @USAGE_ERRORS;
68 # if (1) {
69 #      push @USAGE_ERRORS,"You must pass something";
70 # }
71
72 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
73
74 my %rows;
75 @rows{@ARGV}=(1) x @ARGV;
76
77 my @header;
78 my $row=0;
79 my $output_newline = 0;
80 while (<STDIN>) {
81     chomp;
82     $row++;
83     my @row = split /[\t\s]/, $_;
84     if (!@header) {
85         @header = @row;
86         next;
87     }
88     if (@ARGV and not exists $rows{$row}) {
89         next;
90     }
91     if ($output_newline) {
92         print qq(\n);
93     }
94     for my $i (0..$#row) {
95         print $i <= $#header ?$header[$i]:'???';
96         print ': '.$row[$i].qq(\n);
97     }
98     $output_newline=1;
99 }
100
101
102
103 __END__