#!/usr/bin/perl -wT use strict; use IO::Socket; use HTML::Entities; require './libraryCommon.pl'; unless (@ARGV) { die "Exiting without parameter. (HINT: You need to pass the ISBN)\n"; } unless (testISBN($ARGV[0])) { my $host="xml.amazon.com"; my $port=80; my $buff=""; my $line; my $title=""; my $date=""; my $manufacturer=""; my $author=""; my @author; my $count=0; my $isbn=$ARGV[0]; my $getBook="GET http://$host/onca/xml2?t=webservices-20&dev-t=D3N1ICFCFE4DHV&AsinSearch=$isbn&type=lite&f=xml HTTP/1.0\ \n\n"; my $sock=new IO::Socket::INET(PeerAddr => $host, PeerPort => $port, Proto => 'tcp') or die "Couldn't connect to $host"; $sock->autoflush(1); print $sock $getBook; $count=0; while (<$sock>) { decode_entities($_); if (m%(.*?)%) { $title = $1 } elsif (m%(.*?)%) { $author[$count]=$1; $count++; } elsif (m%.*, (\d\d\d\d)%) { $date=$1; } elsif (m%(.*?)<\/Manufacturer>%) { $manufacturer=$1; } } close($sock); print $title, "\n"; foreach $author (@author) { print $author, "\n" }; print $date, "\n"; print $manufacturer, "\n"; } else { die "Exiting due to the fact that you have supplied an invalid ISBN."; }