Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I extract fields from a CSV file in Perl?

Tags:

csv

perl

I want to extract a particular fields from a csv file (830k records) and store into hash. Is there any fast and easy way to do in Perl with out using any external methods?

How can I achieve that?

like image 871
joe Avatar asked Feb 26 '10 09:02

joe


1 Answers

Use Text::CSV_XS. It's fast, moderately flexible, and extremely well-tested. The answer to many of these questions is something on CPAN. Why spend the time to make something not as good as what a lot of people have already perfected and tested?

If you don't want to use external modules, which is a silly objection, look at the code in Text::CSV_XS and do that. I'm constantly surprised that people think that even though they think they can't use a module they won't use a known and tested solution as example code for the same task.

like image 70
brian d foy Avatar answered Nov 15 '22 04:11

brian d foy