I think you should change the order of operations:
- Extracts the page content using LWP::UserAgent, HTML::TableExtract
- Creates the Excel using Spreadsheet::WriteExcel
- Writes to the excel and closes it
- Lets the user download it
This way you would avoid creating the Excel file if the content recovered is not correct (think getting a 404 from LWP).
I would also consider two things:
- Use XML instead of creating a Excel file: unless your formating and using formulas in the Excel, XML is more portable and probably faster to write using XML::Writer. Newer versions of Excel can work pretty well with XML (unless the XML content is really large).
- If you really need Excel, then assign the content of the file to a scalar instead of an array. If you are at a Windows OS, maybe you should use binmode() before printing it.
Alceu Rodrigues de Freitas Junior
---------------------------------
"You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill