rmckillen has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use LWP::UserAgent; use DBI; $db_database = "db"; $db_uid = "user"; $db_pwd = "pass"; ($ua = LWP::UserAgent->new)->timeout(20); #actually set timeout $dbh = DBI->connect ("DBI:mysql:$db_database".$mysqlsock, $db_uid, $db +_pwd) or die("could not connect to db\n"); $sth = $dbh->prepare("SELECT url FROM files"); $sth -> execute(); $numrows = $sth->rows; $i = 0; $works = 0; $notworks = 0; print "\n\n"; #while (my $url = $sth->fetchrow_array) { while (defined(my $url = $sth->fetchrow_array)) { if(($ua->request(HTTP::Request->new('HEAD', $url)))->is_success()) { $validity = "link works"; $valid_update = $dbh->do("UPDATE files SET valid = 1 WHERE url = '$url +'"); ++$works } else { $validity = "link sucks"; $valid_update = $dbh->do("UPDATE files SET valid = valid + 1 WHERE url + = '$url'"); ++$notworks; } ++$i; print "$i of $numrows\n$validity\n$url\n\n"; } $sth->finish;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: help with link checking
by arturo (Vicar) on Mar 06, 2001 at 23:21 UTC | |
by dws (Chancellor) on Mar 07, 2001 at 05:34 UTC | |
|
Re: help with link checking
by arhuman (Vicar) on Mar 06, 2001 at 23:26 UTC | |
by rmckillen (Novice) on Mar 07, 2001 at 02:11 UTC | |
by merlyn (Sage) on Mar 07, 2001 at 02:14 UTC | |
by rmckillen (Novice) on Mar 07, 2001 at 04:13 UTC | |
by merlyn (Sage) on Mar 07, 2001 at 04:22 UTC |