sub changelog {
if($GMS->getsetting('OTHER','LOGCLEAR') > param("NOWTIME")){
viewlog("Error: Time-Date mismatch.");
exit;
}
my $filename = $GMS->getsetting('FILE','MEMBERDIRL').'/GMS';
open(logfile,"$filename.log") or $GMS->dienice("Unable to open log
+file!");
flock(logfile,2) if($GMS->getsetting('OTHER','FLOCK'));
my $length = scalar(@{[<logfile>]})-1;
seek(logfile,0,0);
my %lines;
for(my $i = 1; $i <= $length+1; $i++){
$lines{$i} = 1 if(param("LINE$i"));
}
open(tempfile,">$filename.tmp") or $GMS->dienice("Unable to open te
+mporary file!");
flock(tempfile,2) if($GMS->getsetting('OTHER','FLOCK'));
seek(tempfile,0,0);
my $count = 0;
while(my $line = <logfile>){
$count++;
if($lines{$count}){
next;
}else{
print STDERR "$count kept\n";
}
print tempfile $line;
}
close(tempfile);
close(logfile);
rename("$filename.log","$filename.bak") or $GMS->dienice();
rename("$filename.tmp","$filename.log") or $GMS->dienice();
unlink("$filename.bak") or $GMS->dienice();
$GMS->changesetting('OTHER','LOGCLEAR',time);
#The GMS object actually does have a filehandle for the 'logfile' i
+n the object
#however, I have tried manually closing it and there was no differe
+nce.
$GMS->logaction("Removed elements from log file");
viewlog("Changes sucessful!");
}
FYI: This is run under 'strict'
Now, this code actually has one of the filehandles still open, however I had tried manually closing it with no effect...
This is only a bit of the code... but I didn't think anyone would want me to send over 2000 lines of code.
Does this clear anything up?
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GIT d- s:++ a--- C++++ UL P+++>++++ L+ E- W++>+++ N !o K- w+ O---- M-- V--
PS PE Y- PGP t++(+++) 5(+++)++++ X R+@ tv+ b+++ DI+ D- G e->+++ h! r-- y-
------END GEEK CODE BLOCK------
Translate
"Weird things happen, get used to it."
Flame ~ Lead Programmer: GMS
|