Posted on 2009-03-03 17:24:08-08 by sardare
smart csv perl reader
Hi, I am a data analyst. I am reading a csv file. Each column in the csv file has a mapping to data based on the column name. e.g. if csv file is something like: key, column_b,column_c,column_d,.. then there is a mapping from column_a to a meaningful name coming from another file: column_a,meaningful_column_a same for column_b, etc.. I need a CSVReader that can be initialized with the mapping files and then be asked to read the csv file, the translation should happen behind the scenes and it should return me mapped column fields. e.g. usage.
my $csvReader = new CSVReader(); $csvReader->initializeMappings(@mapping_files); $csvReader->read($csv_file); while($csvReader->hasNext()) { my @columns = $csvReader->readNext(); }
Is there a library out there that does this smartly and can also take in configuration file specifying how to map column names. If it has other cool features that would be cool too. thanks! Matt
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.