Here's an example of how you can just keep one file with lets say 10 lines.
Once the file reaches the max size, new entries are put at the end and the first line is removed.
#!/usr/bin/perl
my $FILE = $ARGV[0];
my $MAXSIZE=10;
exit -1 if ! -f $FILE;
$num_lines = 0;
open FILE, ">$FILE";
for (;;) {
chomp($mytime=`date +%T`);
my $line = "$mytime";
$line .= ";" . sprintf "%.2f", rand(10);
$line .= ";" . sprintf "%.2f", rand(20);
$line .= ";" . sprintf "%.2f", rand(30);
$line .= ";" . sprintf "%.2f", rand(40);
if($num_lines < $MAXSIZE){
push @array, "$line\n";
$num_lines++;
}else{
shift @array;
push @array, "$line\n";
}
#Get the end position of the file
seek(FILE, 0, 2);
$endpos = tell(FILE);
seek(FILE, 0, 0);#Seek to start
print FILE @array;
#For the rest of the bytes print " "
$curpos = tell(FILE);
for(my $cnt=$curpos;$cnt<$endpos;$cnt++){
print FILE " ";
}
sleep 1;
}
|