Memoize

BasicWerk   EC Support   Technique   Facebook  

20141120221040_Perl_tsv_to_JSON

Perl_tsv_to_JSON

 

 

toJSON.pl
 
#! /usr/bin/perl
use warnings;
use strict;
use JSON;
 
my %out;
while (<>){
    my ($key, @rest) = split;
    $out{$key} = \@rest;
}
 
# 見やすいように { pretty => 1 }
print to_json(\%out, { pretty => 1 });
 

 

 
% cat sample.tsv
aaa	yyy	30
bbb	jjj	70
ccc	k	89
 
% toJSON.pl sample.tsv
{
   "aaa" : [
      "yyy",
      "30"
   ],
   "bbb" : [
      "jjj",
      "70"
   ],
   "ccc" : [
      "k",
      "89"
   ]
}
 

 


© Shin Nakamura/BasicWerk 2014