Hi.
I´ve written a small script which waits for a file to be created. When it finally is created it goes thru some treatment...and finally it´s deleted...and goes back to waiting mode...
The problem is that i´m using a "while"-loop....and it kicks my cpu-usage up to the top (of course) though it´s a small program..
Is there a way to do this in a different and less cpu-consuming way?
Code
#!C:\Perl\bin -w
use CGI;
use strict;
my $html_file_path="testar.txt";
my $template_file_path="infile.txt";
my $log_file_path="outfile.txt";
my $pass;
my $connect;
print "\[HLTV-script is idling\]";
while (!-f $html_file_path)
{
if (-f $html_file_path)
{
open (INFILE, "<$template_file_path"
or die;
my @infile = (<INFILE>);
close (INFILE);
open (HTMLFILE, "<$html_file_path"
or die;
my @htmlfile = (<HTMLFILE>);
close (HTMLFILE);
foreach my $l_ (@htmlfile)
{
if ($l_ =~/^serverpassword/){
$pass=$l_;
}
if ($l_ =~/^connect/){
$connect=$l_;
}
}
open(LOGFILE,">$log_file_path"
or die;
foreach my $line (@infile)
{
$line =~ s/\$serverpassword/$pass/g;
$line =~ s/\$connect/$connect/g;
print LOGFILE $line; # Output line to file
}
unlink $html_file_path;
}
close LOGFILE;
}
I´ve written a small script which waits for a file to be created. When it finally is created it goes thru some treatment...and finally it´s deleted...and goes back to waiting mode...
The problem is that i´m using a "while"-loop....and it kicks my cpu-usage up to the top (of course) though it´s a small program..
Is there a way to do this in a different and less cpu-consuming way?
Code
#!C:\Perl\bin -w
use CGI;
use strict;
my $html_file_path="testar.txt";
my $template_file_path="infile.txt";
my $log_file_path="outfile.txt";
my $pass;
my $connect;
print "\[HLTV-script is idling\]";
while (!-f $html_file_path)
{
if (-f $html_file_path)
{
open (INFILE, "<$template_file_path"
my @infile = (<INFILE>);
close (INFILE);
open (HTMLFILE, "<$html_file_path"
my @htmlfile = (<HTMLFILE>);
close (HTMLFILE);
foreach my $l_ (@htmlfile)
{
if ($l_ =~/^serverpassword/){
$pass=$l_;
}
if ($l_ =~/^connect/){
$connect=$l_;
}
}
open(LOGFILE,">$log_file_path"
foreach my $line (@infile)
{
$line =~ s/\$serverpassword/$pass/g;
$line =~ s/\$connect/$connect/g;
print LOGFILE $line; # Output line to file
}
unlink $html_file_path;
}
close LOGFILE;
}