I have to display a customer's latest eMail drivel on her web page, which I access on my server's mail folder. The code below slpits the text, printing out the body text from the headers and the html mess after, etc.
Thing is, each new message is appended to the file so that I need to get to the LAST messsage to do the extraction.
How do I instruct the scrip to find the LAST instance of the text for splitting?
##################################
I started with nothing, and have most of it left
Thing is, each new message is appended to the file so that I need to get to the LAST messsage to do the extraction.
How do I instruct the scrip to find the LAST instance of the text for splitting?
##################################
Code:
#!/usr/bin/perl
$filename2 = "/usr/local/etc/httpd/htdocs/dancewithdebbie/email.txt";
$filename = "/var/mail/debbienl";
$redirect = "[URL unfurl="true"]http://www.dcdancenet.com/dancewithdebbie/news2.shtml";[/URL]
open(FILE,"$filename");
@lines = <FILE>;
close(FILE);
$start=0;$finish=0;
open(WRITE,">$filename2") || die "Can't open $filename2!\n";
foreach (@lines) {
chomp; #now you can ignore the \n
if ($_ eq "Dance with Debbie") {
$start=1;
}
if ($_ eq "Content-Type: text/html;") {
last;
}
if ($start ==1) {
print WRITE "$_\n"; #add it back in
}
}
close (WRITE);
print "Location: $redirect\n\n";
I started with nothing, and have most of it left