scripts/misc/yaml2csv

26 lines
474 B
Text
Raw Permalink Normal View History

#!/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 );
}