I have been using the Text::CSV module to read csv files and now come to the part where I need to generate a revised csv file, and am confused how to do that.

while ( my $row = $csv->getline( $fh ) ) { $patron_count++; push @rows, $row;

I am fine if I want to keep the whole row:

$csv->print ($fh, $_) for @rows;

but I am confused when I need to modify the '@rows', ie remove some of the columns(fields) or add some new fields on to it.

I am sorry for the basic question, but I am doing some volunteer work for a theatre trying to move from one system to another, and after being away from coding for 8 years, I have forgotten it all!

I think I understand that '@rows' just isn't an array, as I have been accessing the columns by the syntax of $row->2, but now I don't know how to create the structure that the csv writer needs. It wants an array ref and I am lost!

The three things I need to do are:

1. Only use (out of 20 cols, columns 1-10,12,15).

2. Modify the value of col 1 by prefixing the character 'r'

3. Add a new column to each row as i parse it, with a string value for its content.

If I could get help so i can proceed, I would be very thankful. I have read and reread the perl docs on the module but am still lost.


In reply to generating csv file by Anonymous Monk

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.