如何从Perl中的CSV文件中提取字段? [英] How can I extract fields from a CSV file in Perl?

查看:347
本文介绍了如何从Perl中的CSV文件中提取字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从csv文件(830k记录)中提取特定字段并存储到哈希中。在使用任何外部方法时,有没有任何快速和容易的方法来处理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?

如何实现?

推荐答案

使用 Text :: CSV_XS 。它速度快,适度灵活,并且经过非常好的测试。这些问题的答案是CPAN的。为什么花时间做一些不如很多人已经完善和测试的东西?

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?

如果你不想使用外部模块,这是一个愚蠢的异议,看看Text :: CSV_XS中的代码,然后这样做。我不断惊讶的是,人们认为,即使他们认为他们不能使用一个模块,他们不会使用已知和测试的解决方案作为同一任务的示例代码。

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.

这篇关于如何从Perl中的CSV文件中提取字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆