That solution will only work if the data contains no commas or newlines. For a real solution, use Text::CSV_XS or Text::xSV or use DBD::CSV which will additionally handle all of the file locking/opening/closing etc.

It's unclear to me what the OP is asking, but my first interpretation was that he/she is asking not how to insert a *record* as you showed, but how to insert a *field*. If the OP means by that that they want to take an existing CSV file with, say 3 fields and turn it into a table with 4 fields and then populate the fourth field, then none of the modules do that explicitly. One way to do it (assuming the original CSV file uses the first line as column names) would be to manually add the field into the file (e.g. if the top line of the file is "col1,col2,col3" ... just edit it to be "col1,col2,col3,col4", then save the file and use one of the modules to populate the col4 field.


In reply to Re: Re: Adding a field into CSV and populating by jZed
in thread Adding a field into CSV and populating by nickjwest

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.