I have many comments on your code , but Im not really sure what you're trying to accomplish so I'l keep it short.

It seems like you're trying to operate on 2-row blocks? Like if the first row meets some match criteria, then meld it into the next row?

...then maybe break up the file into 2-row blocks and use regexes on each one.. Like split it this way:

my @tworows = split /[^\n]+\n[^[n]+\n/, $text;

then you can just use something like

s/((\w+).+\1.+\1.+)\n(.+)/something/

then repeat that starting on the first even row (because the regex always checks the FIRST row for matches). Much simpler than storing all those temporary arrays, whiles, ifs, etc.

But here are few recomendations:

1. next; } is the same as } 2. Don't make a copy of your row array to use it, just dereference it: my @row1 = @{$row}; # not needed.. Just use $row->[$index] instead of $row1[$index] 3. drop all the extra parens join ';', @arr; push @arr, 'something'; 4. it looks like you're using a numeric == to compare ascii fields lik +e $row1[0] == $row2[0] when col 0 contains things like 'PF'. Use eq f +or these compares. You can't use == there.

In reply to Re: perl: How to comapre and manipulate csv file in perl? by misterperl
in thread perl: How to comapre and manipulate csv file in perl? by Ankur_kuls

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.