i'm a relative PERL newbie looking to tap the wisdom of the monks for the first time. i have working code which:

1. reads in a .csv file with the Text::CSV_XS module
2. sets the columns to friendly variable names for later placement in a here doc
3. performs some string formatting and variable setting based on values in certain columns
4. for each line in the csv, generates a predictable XML doc structure using a simple here doc layout and inserts the field values into the required XML elements
5. outputs a physical XML file to an output directory with a file name which cooresponds to the "order_id" field for each row in the input .csv

input csv file looks like:
order_id, name, item_id, item_desc, price 1, bill smith, 11, red shoes, 39.99 2, john doe, 32, black hat, 21.59 3, jane lee, 12, green shoes, 29.99 2, john doe, 11, red shoes, 39.99
the xml file output for "order_id = 1" should look like:

<order> <order_id>1</order_id> <name>bill smith</name> <item> <item_id>11</item_id> <item_desc>red shoes</item_desc> <price>39.99</price> </item> </order>

the xml file output for "order_id = 2" should look like:
<order> <order_id>2</order_id> <name>john doe</name> <item> <item_id>32</item_id> <item_desc>black hat</item_desc> <price>21.59</price> </item> <item> <item_id>11</item_id> <item_desc>red shoes</item_desc> <price>39.99</price> </item> </order>
in the case of rows with matching "order_id" columns i want to:

1. determine how many matching rows there are in the input .csv
2. create a for loop to output as many new child XML elements as there are duplicate rows in the .csv (i do realize looping and other logic are not allowed inside here docs so i'll need to rethink that)
3. insert only the unique column data from the subsequent matching rows into additional, duplicate child elements (<item>) in the XML document
4. output the XML file to an output directory

hopefully i've provided clear and concise information describing the challenge. thanks for taking a look and for (hopefully) sharing your observations/thoughts on a solution.

In reply to merging .csv text input based on matching column field values in multiple rows by abrg

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.