PDA

View Full Version : print on update


ignoranceisblis
03-17-2005, 05:20 AM
I'm trying to write a script to display a file in realtime
I wrote this simple script to clear the screen and then
cat the file everytime it changes but constantly opening,
reading and closing the file slows the program down
is there an easier way to do this?


#!perl
my $loop ="yes";
my $file ="/home/elliot/file";
while ($loop eq "yes") {
$old="";
open(FILE,"$file");
flock(FILE, LOCK_SH);
seek(FILE, 0, SEEK_SET);
while (my $filechk = <FILE>) {
$old="$old$filechk";
}
close(FILE);
unless($old eq $new) {
system('clear');
system('cat $file`);
}
$new=$old;
}

T.I.A.

rwedge
03-18-2005, 01:13 AM
You should not use a run away loop in programs, as you noted your program slowed down because the cpu is busy running the loop.

What is your goal, why do you need to update often?

/Bob

ignoranceisblis
03-18-2005, 08:35 PM
A few weeks ago I wrote a small a.i. simulator for AIM and IRC
Now I'm trying to build a gui for it using Tk.
I need the update script so that a certain window of the gui can constantly display the bot's buddy list, as it changes.
I already made it so that when ever a buddy sogns on/off there name is added/removed from the file, but iI don't know how to display changes in the file, as they happen.

rwedge
03-20-2005, 04:58 AM
One option may be to put your update check script on a timer to control the resources it uses. Another may be to tie the script that updates the buddie list to the buddie list managment script ( if one is being used ).

Something like this may require a client side refresh using meta tags or javascript. It could slow the browser down if not done in intervals, but it would take the some of the load off the server side.

/Bob