You say "This functionality seems to work improperly for some data." This tells me that you have some data-sets where the functionality works as expected and other data-sets where it does not. To me this sounds like an issue in your data: there are characters in the string that your CSV generator is not coping with properly.

I would start my debugging with the question: "What is the difference between data that works and data that doesn't?"

To answer this question, split up your data-sets into two camps: those that work correctly and those that don't. Take one of the "don't work" camp and pare it down by removing lines until you get down to a line or two that fails. (Binary-spitting will be the tool of choice here -- split the data-set in two pieces and apply the test to each piece; take the piece the failed and repeat the process. This will quickly get you down to a line containing the 'bad' character or characters, but see the note later on).

Look at the data in the line. Are there characters there that you did not expect? Do any of the fields embed your separator character? Are there 'control' characters embedded in one of the fields? Figure out "What Is Wrong Here"....?

Once I have an hypothesis ('When I see XXXX in my data, my CSV generation fails'), I check my other failing data-sets. If they also have the same XXXX character(s), then I feel confident that I have found a Real Bug, one that is common to all of my failing data. Fix the bug. Do your happy-dance. But...

Note: When you do fix the Bug, that is no assurance that you don't have another bug that was masked by the bug you just fixed. You may have to do this process several times before you get a completely clean run. Even then, you may run into other input data later on that cause your CVS generator grief (Naive Users are infinitely imaginative). This is a really good argument for going to CPAN and looking at the CSV modules there -- they are more likely to have all of the 'normal' errors already fixed, and a lot of the edge-cases (ones that you haven't thought of yet) handled as well.

----
I Go Back to Sleep, Now.

OGB


In reply to Re: Problem In generating the CSV file in the perl code using Apache by Old_Gray_Bear
in thread Problem In generating the CSV file in the perl code using Apache by sondagar_nilesh

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.