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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.