Skip to content

Commit

Permalink
new file: tsv2yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Jul 19, 2012
1 parent 868de1d commit 03294d2
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tsv2yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/perl
use strict;
use warnings FATAL => qw(uninitialized);
use Text::CSV;
use Data::Dumper;
use YAML;
use Carp;
#use JSON;

my $csv = Text::CSV->new( { sep_char => "\t" } ) or croak 'Cannot use file: ' . Text::CSV->error_diag();

my @headers;

while (<>) {
my $result = $csv->parse($_);
@headers = $csv->fields();
last;
}

my $data;

while (<>) {
my $result = $csv->parse($_);
my @fields = $csv->fields();
my $count = 0;
for my $field (@fields) {
${$data}{ $fields[0] }{ $headers[$count] } = $field;
$count++;
}
}

print Dump $data;

#my $json = new JSON;
#my $json_text = $json->pretty->encode($data);
#print $json_text;

0 comments on commit 03294d2

Please sign in to comment.