G'day raja567,
Welcome to the monastery.
"I had to kill the script every time, it was running for hours and returning nothing."
You're reading your input from your output file:
open(INPUT,$outFile) or die "Can't open file";
You haven't shown enough of your code but I suspect you have something like this (before the code you have shown):
my $workbook = Spreadsheet::WriteExcel->new($outFile); my $worksheet = $workbook->add_worksheet();
Your code keeps reading what you've just written. You're effectively in an infinite loop.
I'd also recommend you look at open for a better way to open your files (using 3-argument form with a lexical filehandle) and write the die "message" (including the actual filename and $!).
You also appear to have an error with this:
$worksheet->write(0,$colCount,$el,$gFmtBold) ;
That's writing everything to row 0! I suspect this is what you want:
$worksheet->write($rowCount, $colCount, $el, $gFmtBold);
Not an error, but on every iteration of the foreach loop you're setting the width for every column that you've already set:
$worksheet->set_column(0,$colCount,40);
That's possibly a lot of additional processing you don't need. Given the amount of data you're dealing with, that could well be noticeable timewise. Would this not be better:
$worksheet->set_column($colCount, $colCount, 40);
The layout of your code is far from optimal. If you employ a logical scheme of indentation, the logic of your code will be far more apparent. This will help you and anyone else who has to subsequently read it. The "perlstyle - Perl style guide" provides tips on how to do this; you can automate the process with perltidy.
[Disclaimer: I'm not a user of Spreadsheet::WriteExcel. The above information was gleaned by reading the documentation.]
-- Ken
In reply to Re^3: Text file to Excel with perl
by kcott
in thread Text file to Excel with perl
by raja567
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |