WIP: uniproc
[hband-tools.git] / tabdata / csv2td
blob8fc7f15a9225b44aa612b73f2a63a4e77ed836f1
1 #!/usr/bin/env perl
3 =pod
5 =head1 NAME
7 csv2td - Transform CSV to tabular data format.
9 =head1 DESCRIPTION
11 Read CSV data on STDIN.
12 Output tabular data to STDOUT.
14 =head1 OPTIONS
16 Any option which Text::CSV(3pm) takes.
17 See C<Text::CSV->known_attributes> for extensive list.
18 Example:
20 csv2td --sep=';' --blank-is-undef=0 --binary
22 becomes:
24 Text::CSV->new({sep=>";", blank_is_undef=>0, binary=>1})
26 =head1 SEE ALSO
28 csv2(1), mrkv2td(1)
30 =cut
33 use Text::CSV qw/csv/;
34 use Data::Dumper;
35 no if ($] >= 5.018), 'warnings' => 'experimental::smartmatch';
36 do '/usr/lib/tool/perl5/tabdata/common.pl' or die "$@";
39 %csv_opts = ();
41 for (@ARGV)
43 if(my ($optname, $value) = /^--([^=]+)(?:=(.*)|)$/)
45 $value = 1 if not defined $value;
46 $optname =~ s/-/_/g;
47 $csv_opts{$optname} = $value;
49 else
51 die "$0: unknown argument: $_\n";
55 $Data = csv(in=>\*STDIN, %csv_opts);
57 for my $row (@$Data)
59 print join($FS, map {escape_tabdata($_)} @$row).$RS;