Hello CSharma. CSV data is flat, so there is no straightforward way to represent nested structures. You can still come up with a representation for your structure (eg: database-like representation with several tables and indexes from one table to another), but you'll have to define it first so that we can understand what you're doing. To do that, please write a simple example, a structure with dummy (but short) data and what you except to find in your CSV. I haven't tried to understand your current structure because of how long it is.

The code you have provided does not check anywhere if all attributes defined in one element are the same in the following, this may be the case, but you have to be sure about it to avoid some values being shifted left or right. If the members of the elements you need to represent are fixed, or you know the list of attributes beforehand, you can iterate over a fixed list of keys, in the other case another strategy might be required (like writing each new attribute at the end of table).


In reply to Re: How to write complete hash into CSV? by Eily
in thread How to write complete hash into CSV? by CSharma

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.