use strict; use LWP::Simple; use DB_File; use Digest::MD5 qw(md5_hex); my $alert_amount = 0.1; # difference to alert my @sites = ( 'http://www.herdofsheep.com', 'http://www.theonion.com', 'http://news.bbc.co.uk', ); my $db_file = 'sites.db'; my (%sites_db); tie %sites_db, "DB_File", "$db_file", O_RDWR|O_CREAT or die "Cannot open database '$db_file': $!"; foreach (@sites) { my ($lines, $matches, $new_entry); my %new = map { md5_hex($_) => 1 } split(/<.*?>/, get($_)); unless (%new) {print "Could not get $_\n"; next} my %old = map { $_ => 1 } split(',', $sites_db{$_}) if exists($sites_db{$_}); foreach (keys %new) { $lines++; $new_entry .= $_ . ','; $matches++ if $old{$_}; } if ((($lines - $matches) / $lines) > $alert_amount ) { print "$_ seems to be different\n"; $sites_db{$_} = $new_entry; } }