in reply to Need help to parse a csv file

Something similar to this would work.

use Text::CSV; use warnings; use strict; # Reading the first file and extracting IVAL...S my $csv = Text::CSV->new; my @header = $csv->getline(\*DATA); $csv->column_names(@header); my $frst = $csv->getline_hr(\*DATA); my ($ivaldate, $ivalstart, $ivalend) = map { $frst->{$_} } qw( IVALDAT +E IVALSTART IVALEND ); # Reading all the rest my $line = <DATA>; $line =~ s/,/\t/g; print join "\t", qw( Date StartTime EndTime), $line; while ($line = <DATA>) { $line =~ s/,/\t/g; print join "\t", $ivaldate, $ivalstart, $ivalend, $line; } __DATA__ "CLLI","SWREL","RPTDATE","RPTIME","TZ","RPTTYPE","RPTPD","IVALDATE","I +VALSTART","IVALEND","NUMENTIDS" "toroonxn0dw","EAGLE5 40.1.0-62.13.19","2009-11-13","19:00:23","EST ", +"STP SYSTEM TOTAL MEASUREMENTS ON TT","LAST","2009-11-13","18:45:00", +"19:00:00",256 "STATUS","TT","GTTPERFD","GTTUN0NS","GTTUN1NT","AGTTPERFD" "K","0",0,0,0,0 "K","1",0,0,0,0 "K","2",0,0,0,0 "K","3",0,0,0,0 "K","4",0,0,0,0 "K","5",0,0,0,0 "K","6",0,0,0,0 "K","7",0,0,0,0

Replies are listed 'Best First'.
Re^2: Need help to parse a csv file
by Anonymous Monk on Nov 17, 2009 at 23:35 UTC
    Oh no, you should also use Text::CSV for # Reading all the rest.

      That is left as an exercise to the reader. :)

        Then why provide code to do it?