Guest User

Untitled

a guest
Dec 9th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #!/usr/bin/env perl
  2. use Modern::Perl;
  3. use Store::CouchDB;
  4. use JSON;
  5. use File::Slurp;
  6.  
  7. # unbuffer output to line up stderr/stdout
  8.  
  9. $|=1;
  10.  
  11. # my $parser = JSON->new->use_utf8->decode;
  12.  
  13. my $couch = Store::CouchDB->new();
  14. $couch->config({host => 'localhost',
  15. port => '5984',
  16. user => 'admin',
  17. pass => 'passwd',
  18. db => 'yourdb'});
  19.  
  20. # processing sample output
  21. # my $doc = $couch->get_doc({id => 'master'});
  22. # say JSON->new->pretty->utf8->encode($doc);
  23.  
  24. # read filenames from argv
  25. while (my $json = shift @ARGV) {
  26. chomp $json;
  27. my ($data, $doc);
  28. say "[$json]";
  29. $data = read_file $json
  30. or die "$! unable to read $json\n";
  31. say "reading...OK";
  32. $doc = decode_json $data
  33. or die "$! unable to parse $json\n";
  34. say "parsing...OK";
  35. $couch->put_doc({doc => $doc})
  36. or die "$! unable to PUT $json\n";
  37. say "storing...OK";
  38. }
  39. exit 0;
Add Comment
Please, Sign In to add comment