Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Need help to parse a csv file

by przemo (Scribe)
on Nov 17, 2009 at 21:30 UTC ( [id://807809]=note: print w/replies, xml ) Need Help??


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?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://807809]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-18 23:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found