Please consider building and manipulating the entire data structure in an array step by step, it makes it easier because you can see what you are doing with pp().

use feature ":5.14"; use warnings FATAL => qw(all); use strict; use Data::Dump qw(dump pp); use Text::CSV_XS; # So original data look something like: my @d = split /\n/, <<'END'; 1,6064.86,85391.25,593.75,13.25 2,6072.17,85392.95,593.79,13.29 3,6078.94,85393.05,593.76,13.26 4,6085.51,85392.22,593.77,13.27 END # I need to insert two lines at the top, two lines at the # bottom, switch columns 2 and 3 around and replace column 5 with colu +mn # 1.I'm using Text::CSV for parsing and also Lava GUI package. So part + of # the code that does parsing looks like this:D my ($t, @t) = (Text::CSV_XS->new); $t->parse($_) && push(@t, [($t->fields())[4,2,1,3,0]]) or die "Could n +ot parse: $_" for @d; # Parse and rearrange unshift @t, ["Top line 1"], ["Top line 2"]; # Top lines push @t, ["Bot line 1"], ["Bot line 2"]; # Bottom lines $t->combine(@$_) && ($_ = $t->string) or die "Cannot combine: ".dump( +$_) for @t; # Combine pp(\@t); # Print result

Produces

[ "\"Top line 1\"", "\"Top line 2\"", "13.25,85391.25,6064.86,593.75,1", "13.29,85392.95,6072.17,593.79,2", "13.26,85393.05,6078.94,593.76,3", "13.27,85392.22,6085.51,593.77,4", "\"Bot line 1\"", "\"Bot line 2\"", ]

In reply to Re: Parsing CSV only returns the second line of the file by philiprbrenan
in thread Parsing CSV only returns the second line of the file by saint_geser

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.