Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I have a problem with file size calculation when I create .xls file using Spreadsheet::WriteExcel
File is created properly and after that I want to email that file to customer.
When I tried to print the file size once its created, getting "0" size.
if I check that in directory, I can see the file with exact size.
Can anyone tell me what's wrong in this code and how to resolve this issue?
Here is my code

use strict; use Spreadsheet::WriteExcel; # Create a new Excel workbook called result.xls my $workbook = Spreadsheet::WriteExcel->new("result.xls"); # Add some worksheets my $sheet = $workbook->add_worksheet("Example"); # Add a Format my $format = $workbook->add_format(); $format->set_align('left'); # Set the width of the column in Sheet $sheet->set_column(0, 5, 30); # Set Sheet as the active worksheet $sheet->activate(); open(FH,"<file1.csv") or die "Cannot read\n"; my($row)=0; while (<FH>) { chomp($_); my(@info) = split(/,/,$_); my $col = 0; foreach my $token (@info) { $sheet->write($row, $col, $token, $format); $col++; } $row++; } close(FH); print "Before sleep\n"; sleep(10); my $filesize = -s "result.xls"; print "Size: $filesize\n"; exit;

Replies are listed 'Best First'.
Re: Getting file size Zero
by olus (Curate) on Mar 13, 2008 at 11:52 UTC

    From the docs

    An explicit close() is required if the file must be closed prior to performing some external action on it such as copying it, reading its size or attaching it to an email.
Re: Getting file size Zero
by BrowserUk (Patriarch) on Mar 13, 2008 at 12:09 UTC

    Try calling the ->close() method first. From the docs:

    An explicit close() is required if the file must be closed prior to performing some external action on it such as copying it, reading its size or attaching it to an email.

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.