OK, so your script will slurp in all of the lines from the file that your monitoring...once. You need to move the open and reading of the data into the while ($hours < 72) loop. In addition, you probably don't want to hold the file open for the whole hour that you're sleeping, so you'd likely want to close it after the data is read.
I'm not real sure why the while ($timer < 1) loop is there since it will always be incremented up to 1 the first time through the loop.
Since you're on Windows, tail -25 probably isn't a good option (Code reuse can be a good thing, performance isn't really an issue since it only runs once an hour), but the sending/printing of the lines could be cleaned up a bunch:
map {print; smtp->datasend($_)} reverse splice(@lines, -25);
will do the same thing (almost, you didn't chomp the data in @lines, so there were double newlines on the copy of the data that went to STDOUT). And if you want the data in the same order it was in the file, remove the 'reverse'.
However, I kind of doubt that you would really want to see the same 25 lines every hour if there has been no change to the file. What you probably want to do is do a select() on fh to see if it has any new data available to be read. Warning: I have done most, if not all of my Perl hacking on a Unix-like version of Perl (Linux, Solaris, AIX, Cygwin, etc), so I don't know if select() is even supported under (I assume) ActiveState on Windows.
If you can use select() or better yet IO::Select, you would do something like this: Open the file;
Create an IO::Select object that watches fh;
while ($hours < 72){
if (IO::Select object->can_read(short_timeout){
read all available data
ship off the last 25 lines in a mail
}
sleep;
}
You should also use IO::Select to check to see if the user entered q. This could be done in the same IO::Select object that watches fh if you only want to check it every hour. More than likely, you'll want a new IO::Select object that you can do a can_read(3600) call on to do your sleep for you.
I'd likely go into more detail, but I'd like to make sure that you can use these calls in your environment before I do. |