in reply to While I'm away...
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:
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'.map {print; smtp->datasend($_)} reverse splice(@lines, -25);
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:
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.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; }
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: While I'm away...
by Poetic Justice (Monk) on Jul 11, 2001 at 06:36 UTC |