#!/opt/perl/bin/perl # this file just merges all json files (which contain a hash) # are given on the command line arguments together and will # print them out on stdout. # # mergejsonhash /tmp/face.json /tmp/face2.json > /tmp/allface.json use JSON::Syck; my %merge; for (@ARGV) { open my $f, $_ or die "$_: $!"; my $h = JSON::Syck::Load (do { local $/; <$f> }); for (keys %$h) { warn "key '$_' already present\n" if $merge{$_}; $merge{$_} = $h->{$_}; } } my $first = 1; print "{"; for (keys %merge) { print "," unless $first; $first = 0; print "\n\"$_\":\"$merge{$_}\""; } print "\n}\n";