beth, countzero, wol thanks for your help/encouragement.

before i go much further, i should post the actual working code i currently have which has been modified to fit the input/output scenario above.

#!/usr/bin/perl use strict; use warnings; use Text::CSV_XS; my $csv = Text::CSV_XS->new(); my $file = ''; if (defined $ARGV[0]) { $file = $ARGV[0]; } open(my $data, '<', $file) or die "Could not open '$file'\n"; while (my $line = <$data>) { if ($csv->parse($line)) { my @columns = $csv->fields(); ## set vars my $orderNumber = $columns[0]; my $name = $columns[1]; my $itemId = $columns[2]; my $itemDesc = $columns[3]; my $price = $columns[4]; open (OUTFILE, "> output/$orderNumber.xml") or die $! . " can' +t open the file\n"; #print OUTFILE <<XML; print OUTFILE "<order>\n"; print OUTFILE " <order_id>$orderNumber</order_id>\n"; print OUTFILE " <name>$name</name>\n"; print OUTFILE " <item>\n"; print OUTFILE " <item_id>$itemId</item_id>\n"; print OUTFILE " <item_desc>$itemDesc</item_desc>\n"; print OUTFILE " <price>$price</price>\n"; print OUTFILE " </item>\n"; print OUTFILE "</order>\n"; #XML close (OUTFILE); } else { warn "Line could not be parsed:\n"; } }
i've read the sort documentation but i'm still having trouble wrapping my brain around how to actually execute it with the Text::CSV module (forgive me, i realize this is a pretty basic concept). the File::Sort module seems interesting, though, i feel i should be able to solve this natively in PERL (also encountering some strange issues when trying to run this module). essentially, how do i get at the file array and then look inside it to the first column's value on each row?

it would appear that my input file is being defined in scalar context where it should be an array. am i getting warmer? ;)

thanks again

In reply to Re^2: merging .csv text input based on matching column field values in multiple rows by abrg
in thread 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.