# Takes raw cuecat output and looks up the barcode scanned # through upcdatabase.com # I DID NOT WRITE THE SECTION THAT DOES THE DECODING # and at the moment the name of the person who did escapes # me use LWP::Simple; $seq = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-'; sub decode { ($encoded) = @_; @s = map { index($seq,$_); } split(//,$encoded); $l = ($#s+1) % 4; if ($l) { if ($l == 1) { print "Error!"; return; } $l = 4-$l; $#s += $l; } $r = ''; while ($#s >= 0) { $n = (($s[0] << 6 | $s[1]) << 6 | $s[2]) << 6 | $s[3]; $r .=chr(($n >> 16) ^ 67) . chr(($n >> 8 & 255) ^ 67) . chr(($n & 255) ^ 67); @s = @s[4..$#s]; } $r = substr($r,0,length($r)-$l); return $r; } chomp($s = ); @fields = split(/\./,$s); @results = map(decode($_), @fields[1..$#fields]); $code = $results[2]; $upcdata = get("http://www.upcdatabase.com/item.pl?upc=$code"); $upcdata =~ s/<(?:[^>'"]*|(['"]).*?\1)*>//gs; $upcdata =~ /Description(.*)\n/; print "\n\n$1\n"; $upcdata =~ /Manufacturer(.*)\n/; print "Made by: $1\n"; $upcdata =~ /Size\/Weight(.*)\n/; print "Size: $1";