Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- use Modern::Perl;
- use Store::CouchDB;
- use JSON;
- use File::Slurp;
- # unbuffer output to line up stderr/stdout
- $|=1;
- # my $parser = JSON->new->use_utf8->decode;
- my $couch = Store::CouchDB->new();
- $couch->config({host => 'localhost',
- port => '5984',
- user => 'admin',
- pass => 'passwd',
- db => 'yourdb'});
- # processing sample output
- # my $doc = $couch->get_doc({id => 'master'});
- # say JSON->new->pretty->utf8->encode($doc);
- # read filenames from argv
- while (my $json = shift @ARGV) {
- chomp $json;
- my ($data, $doc);
- say "[$json]";
- $data = read_file $json
- or die "$! unable to read $json\n";
- say "reading...OK";
- $doc = decode_json $data
- or die "$! unable to parse $json\n";
- say "parsing...OK";
- $couch->put_doc({doc => $doc})
- or die "$! unable to PUT $json\n";
- say "storing...OK";
- }
- exit 0;
Add Comment
Please, Sign In to add comment