You can check the size of the file using the -s operator.
use strict;
use warnings;
use File::Slurp qw(read_file write_file);
use Spreadsheet::ParseExcel;
use Spreadsheet::ParseExcel::SaveParser;
use Spreadsheet::WriteExcel;
my $file = 'path_to_file';
my $size_file = 'path_to_file_keeping_the_size';
my $excel_file = 'path_to_excel_file.xls';
my $current_size = -s $file;
my $old_size = 0;
if (-e $size_file) {
$old_size = read_file($size_file);
}
if ($old_size new;
my $excel = $parser->Parse($excel_file);
my $row = 1;
$row++ while $excel->{Worksheet}[0]->{Cells}[$row][0];
$excel->AddCell(0, $row, 0, scalar(localtime));
$excel->AddCell(0, $row, 1, $current_size);
my $workbook = $excel->SaveAs($excel_file);
$workbook->close;
} else {
my $workbook = Spreadsheet::WriteExcel->new($excel_file);
my $worksheet = $workbook->add_worksheet();
$worksheet->write(0, 0, 'Date');
$worksheet->write(0, 1, 'Size');
$worksheet->write(1, 0, scalar(localtime));
$worksheet->write(1, 1, $current_size);
$workbook->close;
}
}
write_file($size_file, $current_size);
A simple way to write Excel files would be using
Spreadsheet::Write.
but if you need to update an existing Excel file you should look into
Spreadsheet::ParseExcel.