Does not seem to be working. I am using a test file with only five lines in it for now (the actual file will have millions of records). Here is the error I'm getting using your line -

Use of uninitialized value in join or string at AlterDataNew.pl line 2 +9, <$FH> line 5. Use of uninitialized value in join or string at AlterDataNew.pl line 2 +9, <$FH> line 5. Use of uninitialized value in join or string at AlterDataNew.pl line 2 +9, <$FH> line 5. Use of uninitialized value in join or string at AlterDataNew.pl line 2 +9, <$FH> line 5. Use of uninitialized value in join or string at AlterDataNew.pl line 2 +9, <$FH> line 5. Use of uninitialized value in join or string at AlterDataNew.pl line 2 +9, <$FH> line 5. Error parsing time at /usr/perl5/5.12/lib/sun4-solaris-64int/Time/Piec +e.pm line 470, <$FH> line 5.

And here is the entirety of my script currently with your line added -

#!/usr/bin/perl/ use strict; use warnings; use Data::Dumper; use Time::Piece; my $filename = 'tested.csv'; open my $FH, $filename or die "Could not read from $filename <$!>, program halting."; # Read the header line. chomp(my $line = <$FH>); my $i = 0; $line = join '', grep { $i++ % 2 ? {s/,/ /g} : 1} split /"/,$line; my @fields = split(/,/, $line); print Dumper(@fields), $/; my @data; # Read the lines one by one. while($line = <$FH>) { # split the fields, concatenate the first three fields, # and add it to the beginning of each line in the file chomp($line); my @fields = split(/,/, $line); unshift @fields, join '_', @fields[0..2]; $_ = join '-', (split /\//)[2,0,1] for @fields[14,20,23]; $_ = Time::Piece->strptime($_,'%m/%d/%Y %H:%M')->strftime('%Y-%m-% +d %H:%M') for @fields[38,39]; push @data, \@fields; } close $FH; print "Unsorted:\n", Dumper(@data); #, $/; @data = sort { $a->[0] cmp $b->[0] || $a->[20] cmp $b->[20] || $a->[23] cmp $b->[23] || $a->[26] cmp $b-> [26] } @data; open my $OFH, '>', '/swpkg/shared/batch_processing/mistints/parsedMist +ints.csv'; print $OFH join(',', @$_), $/ for @data; close $OFH; exit;


In reply to Re^4: Replace commas with spaces between quotes, parsing CSV by BigRedEO
in thread Replace commas with spaces between quotes, parsing CSV by BigRedEO

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.