CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate: Re: [sat110] Limit alerts to 3 max: Edit Log


Feb 11, 2009, 10:35 PM

Views: 22870
Re: [sat110] Limit alerts to 3 max

When you have a true/false condition you can just use a binary flag. In perl, 0 (zero) is a false value, and 1 (or any number or string) is true. So you can do this:


use CGI::Carp qw(fatalsToBrowser);
use LWP::UserAgent;

my $ua = new LWP::UserAgent;
my $req = new HTTP::Request('GET', 'http://www.yourdomain/test.html');
my $res = $ua->request($req);

# Check if the requested webpage is there
if ($res->is_success) { # Request successful
$webpage = $res->content; # Store the page in the string $webpage

@webpage = split(/\n/,$webpage);
$found = 0;#false
foreach $line (@webpage) {

# Below is the text you want to look for (I use the date)
# Example looking for 12/20/08
if ($line =~ /12\/20\/08/) {
$found = 1;#true
# Ok, we found a webpage with the above text in the HTML-code.
# So the webpage we are watching has not changed

my $n = 0;
open (FH, "<", '/fullpathto/alert-count.txt') or die "$!";
$n = <FH>;
close FH;
if ($n < 3) {
open (FH, ">", '/fullpathto/alert-count.txt') or die "$!";
print FH ++$n;
close FH;
else {
exit(0); #<---here your program might exit before sending an email
#your existing code here

if ($found) {
# Write the alert-email
$mailprog = '/usr/sbin/sendmail -oeq -t';
$recipient = '';
$sender = '';
open (MAIL, "|$mailprog");
print MAIL "To: $recipient\n";
print MAIL "From: $sender\n";
print MAIL "Subject: Schedule Page Updated or down\n\n";
print MAIL "NEW Basketball schedule may be posted.";
print MAIL "Must Call ASAP.";
close (MAIL);



(This post was edited by KevinR on Feb 11, 2009, 10:35 PM)

Edit Log:
Post edited by KevinR (Veteran) on Feb 11, 2009, 10:35 PM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives