Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl -Tw use Carp; use DB_File; use Digest::MD5 qw/md5_hex/; use Fcntl qw/:flock/; use HTTP::Request; use LWP::UserAgent; use URI; use strict; # %despatch_table hash # # The keys of this hash specify the web page to monitor, # with the corresponding hash values containing references # to the script method or subroutine to be executed upon # change in the web page. # my %despatch_table = ( '' => + 'virus_alert' ); # Create a DBM hash containing the last modification time # or page MD5 hash, indexed by the page URL my %index; my $db = tie %index, 'DB_File', "wpmon.dbm", O_CREAT | O_RDWR, 0666; my $fd = $db->fd(); open (DF, "+<&=$fd") || croak $!; flock (DF, LOCK_EX) || croak $!; # Add any new keys within %despatch_table to the array # of URLs to monitor my @urls = keys %index; foreach my $url (keys %despatch_table) { push (@urls, $url) unless (exists $index{$url}); } my $ua = LWP::UserAgent->new; foreach my $url (sort @urls) { my $uri = URI->new($url); my $request = HTTP::Request->new('GET', $uri->canonical->as_string +); my $response = $ua->request($request); if ($response->is_success) { # Update measure for page is last_modified header if # defined or failing this, an MD5 digest of the page my $html = $response->content; my $unique = $response->last_modified || md5_hex($html); $index{$url} = $unique unless (exists $index{$url}); if ($index{$url} ne $unique) { # Ensure that a code or method reference still exists # within the %despatch_table hash - If so, execute it # via an eval statement if (exists $despatch_table{$url}) { $html = quotemeta $html; eval qq/ $despatch_table{$url}("$html") /; carp $@ if $@; } $index{$url} = $unique; } } } undef $db; untie %index; close DF; exit 0; sub virus_alert { # ... response code to changed web page within subroutines }

In reply to Scripted Actions upon Page Changes by rob_au

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (5)
    As of 2018-02-20 09:54 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (268 votes). Check out past polls.