I have a script which has been working wonderfully for about a week now while I have been developing around it. Unfortunately it is now hanging. The script is as follows:
#!/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 p +ass the I\ SBN)\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 $count=0; my $isbn=$ARGV[0]; my $getBook="GET http://$host/onca/xml2?t=webservices-20&dev-t=D3N +1ICFCFE4DHV&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; print <$sock>; while (<$sock>) { print "looping. \n"; decode_entities($_); print $_, "\n"; if (m%<ProductName>(.*?)</ProductName>%) { $title = $1 } elsif (m%<Author>(.*?)</Author>%) { $author[$count]=$1; $count++; } elsif (m%<ReleaseDate>.*, (\d\d\d\d)</ReleaseDate>%) { $date=$ +1; } elsif (m%<Manufacturer>(.*?)<\/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."; }
I have tested the code through and everything is fine except the "while(<$sock>){}" loop. If I remove this loop the script simple runs to completion. With this loop in place the script hangs. Any print statements that I put in the loop are not displayed.
I have tried directly connecting to: here, which does seem to produce a lovely page of XML information about the book requested.
Why would my script hang while trying to read this page? Any suggestions?
~~Guildencrantz
In reply to Reading an XML page by Guildencrantz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |