#!/usr/bin/perl use JSON::XS; use List::Util qw(shuffle); use Digest::MD5 qw(md5_hex); foreach $file (glob($ARGV[0])){ print "Processing $file...\n"; $json = ''; open(FILE, $file); read(FILE, $json, (-s FILE)); close(FILE); undef($JSONREF); eval { $JSONREF = decode_json $json; }; if (!defined($JSONREF)) { print "BAD($file)\n"; next; } foreach $entry (@{$JSONREF->{'responses'}[0]->{'webDetection'}->{'fullMatchingImages'}}) { $HASH{$entry->{'url'}}++; } foreach $entry (@{$JSONREF->{'responses'}[0]->{'webDetection'}->{'partialMatchingImages'}}) { $HASH{$entry->{'url'}}++; } } #randomize the image URL list... @ARR = keys %HASH; @ARR = shuffle(@ARR); #and write out the randomized image list... open(OUT, ">./MASTERIMAGELIST.TXT"); foreach $url (keys %HASH) { $file = md5_hex($url); print OUT "$url\t$file\n"; } close(OUT);