I have a similar script that uses LWP::Simple, Digest::MD5 and DBI. I basically store the page checksum in the DB, which is a pretty good method to check if the file has changed. Comparing the full page is kinda overkill IMHO.
Update: pretty similar to mr.nick's solution above...
Update2: I was actually considering posting this under CUFP a few days ago...
#!/usr/bin/perl -w use strict; use DBI; use LWP::Simple; use Digest::MD5 qw(md5 md5_hex md5_base64); my $dbh = DBI->connect("dbi:mysql:database", "user", "password") || di +e "Can't connect"; my $sth = $dbh->prepare("select url from sites"); $sth->execute(); my $url = undef; $sth->bind_col(1,\$url); my @urls = (); while($sth->fetch()) { push(@urls, $url); } $sth->finish(); if (@ARGV) { my $url = $ARGV[0]; my $page = get($url); my ($title) = $page =~ /<TITLE>(.*?)<\/TITLE>/i; my $digest = md5_hex($page); my $date = time(); $title =~ s/\'/\\\'/g; my $q = join ("','",$title,$url,$digest,$date); $q = "'".$q."'"; $sth = $dbh->prepare("insert into sites values ('$title','$url','$di +gest','$date')"); $sth->execute(); } $sth->finish(); foreach my $url (@urls) { my $page = get($url); print $url,"\n"; my $digest = md5_hex($page); $sth = $dbh->prepare("select checksum from sites where url = '$url'" +); $sth->execute(); my $checksum = undef; $sth->bind_col(1,\$checksum); while($sth->fetch) { if ($checksum ne $digest) { my $date = time(); my ($title) = $page =~ /<TITLE>(.*?)<\/TITLE>/i; my $q = qq|url = "$url", name = "$title", checksum = "$digest", +date = "$date"|; my $sth2 = $dbh->prepare("update sites set $q where url = '$url' +"); $sth2->execute(); } } $sth->finish(); } $dbh->disconnect || die "Disconnection failed";

Greetz
Beatnik
... Quidquid perl dictum sit, altum viditur.

In reply to Re: Compare file content with a variable content by Beatnik
in thread Compare file content with a variable content by Skyhawlk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.