I am trying to check a short list of URLs in a MySQL DB to see if they are valid. Here is the code I am using:
my($sth) = $dbh->prepare($query);
$sth->execute || die("Could not execute!");
while(@row = $sth->fetchrow) {
$whereto = $row[0];
&letsgo;
}
exit;
sub letsgo {
$ua->agent("Mozilla/8.0");
$req = new HTTP::Request 'GET' => '$whereto';
# send request
$res = $ua->request($req);
if ($res->is_success) {
print "It worked\n";
} else {
print "Error: " . $res->code . " " . $res->message;
print "It failed\n";
}
}
It always fails BUT if I change
to something like
It works. What am I missing?
Code:
my($query) = "SELECT weburl FROM table where condition = '1'"; my($sth) = $dbh->prepare($query);
$sth->execute || die("Could not execute!");
while(@row = $sth->fetchrow) {
$whereto = $row[0];
&letsgo;
}
exit;
sub letsgo {
$ua->agent("Mozilla/8.0");
$req = new HTTP::Request 'GET' => '$whereto';
# send request
$res = $ua->request($req);
if ($res->is_success) {
print "It worked\n";
} else {
print "Error: " . $res->code . " " . $res->message;
print "It failed\n";
}
}
It always fails BUT if I change
Code:
$req = new HTTP::Request 'GET' => '$whereto';to something like
Code:
$req = new HTTP::Request 'GET' => 'http://www.gossamer-threads.com';It works. What am I missing?