Initial check-in of yaml2csv and collapse scripts

This commit is contained in:
Ray Miller 2011-08-12 15:06:00 +01:00
parent a40cdd4259
commit 2459a14ea3
2 changed files with 48 additions and 0 deletions

25
yaml2csv Executable file
View file

@ -0,0 +1,25 @@
#!/usr/bin/env perl
use strict;
use warnings FATAL => 'all';
use YAML::Any;
use CSV::Writer;
use Getopt::Long;
my @columns;
GetOptions(
'columns=s@' => sub {
my ( $opt, $value ) = @_;
push @columns, split qr{\s*,\s*}, $value;
}
) and @columns > 0
or die "Usage: $0 [--columns=...]\n";
my $csv = CSV::Writer->new( columns => \@columns );
$csv->write( $csv->columns );
for my $d ( YAML::Any::LoadFile( \*STDIN ) ) {
$csv->write( $d );
}