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

I want to create a new spreadsheet each time due to changing data requirements. There will be an existing spreadsheet with the same name so my thought was to delete the exisiting spreadhseet and start fresh but this is not working. Unless I physically remove the existing file first the same data keeps showing up. I tried renameing the "trend report" directory to "trend_report" but this didn't work also. Can you help me get past this hurrled so I can started?
#!/usr/bin/perl use Spreadsheet::WriteExcel; $file = "/web/htdocs/osdsun80.ameritech.com/eadas/West/trend report/We +st.xls"; if (-r "$file") { unlink("$file") or die "Can't Unlink $file: $!"; } # Create a new workbook and add a worksheet my $workbook = Spreadsheet::WriteExcel->new("$file"); my $worksheet = $workbook->addworksheet("West Trend");

Replies are listed 'Best First'.
Re: New Spreadsheet
by dragonchild (Archbishop) on Dec 08, 2004 at 18:08 UTC
    First, why not use Excel::Template?

    Second, -r checks to see if it's readable by you, not if it exists or is a file. I would use -e or -f, not -r.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      Guess what... it seems that the -r worked fine and infact the data was getting updated but I needed to close my browser and re-open it. Is there something that can be added to the code to prevent this?
        If you're using a browser, then there is no reason to create a file on your server, then serving that file. You can stream the buffer to the web browser.

        Being right, does not endow the right to be rude; politeness costs nothing.
        Being unknowing, is not the same as being stupid.
        Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
        Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

        Spreadsheet...browser? I'm not getting what one has to do with the other. Are you creating the spreadsheet through a CGI and then downloading it? Or is there some voodoo that allows one to view the contents of a spreadsheet through a browser?

        thor

        Feel the white light, the light within
        Be your own disciple, fan the sparks of will
        For all of us waiting, your kingdom will come

Re: New Spreadsheet
by ikegami (Patriarch) on Dec 08, 2004 at 19:33 UTC

    This won't fix your problem, but don't do "$file", just use $file. There is no reason to put a variable in quotes (unless you're building a string like in the die argument).