This is my first ever Perl script (!) The script is supposed to continously query google for hits on the "search google for this string" and store the returnde URLs to database. In the scipt below it should query 5 times (0-50 hits, 10 hits returned per query) however if i set the loop to run till $counter<20 it loops up to 30, if I loop till $counter<50 it actually loops until 70, etc As far as I can gather - Im "looping to much" and I think the problem has to do with the search->response being either array or ref array ... Im not at all familiar with these.
I suspect something needs to be reset to an empty array - I have a feeling its accumulating all previous results along with each new loop ... use Net::Google; use DBI; use constant LOCAL_GOOGLE_KEY => "My Google Key"; my $google = Net::Google->new(key=>LOCAL_GOOGLE_KEY); my $search = $google->search(); my $counter = 0; my $dbh = DBI->connect ('dbi:mysql:choogle', 'soren', 'letmein') || die "Couldn't open DB connection."; while ($counter<50) { $search->query("search google for this string"); $search->lr(qw(da)); # danish $search->ie("utf8"); $search->oe("utf8"); $search->starts_at($counter); $search->max_results($counter+10); $search->restrict(qw(countryDK)); foreach my $r (@{$search->response()}) { # Loop search response print "Now collecting results ".$counter." to ".$counter+10; foreach my $element (@{$r->resultElements()}) { # Loop resultElements $dbh->do ("INSERT IGNORE INTO temp_hits VALUES (". '"'.$element->URL().'", '. '"'.$element->title().'", '. 'NOW(), '. '"'.$search->query().'")') || die ("Couldn't write to DB"); } $counter = $counter + 10; } } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]