使用perl比较两个csv文件 [英] Compare Two csv files using perl

查看:107
本文介绍了使用perl比较两个csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




任何人都可以帮我编写Perl中的脚本来比较两个csv文件,并选出显示差异的记录吗?


任何回复都将不胜感激。


谢谢,

Vasuki

Hi,

Can any one help me in writing a script in Perl to compare two csv files and pick out the records which show differences?

Any responses would be appreciated.

Thanks,
Vasuki

推荐答案

发布你当前的代码,有人可能会帮忙。
post your current code and someone will probably help.


我试过并获得了整个脚本。现在工作正常。请找到下面的脚本。

I tried and got the entire script. It is work fine now. Please find the script below.

展开 | 选择 | Wrap | 行号


当然,它很慢。你正在为file1中的每一行扫描file2的大部分内容。这意味着你的执行时间是相对于文件大小的平方。


现在忽略你当前的算法,我建议你查看一个cpan模块为你做这件事。


cpan Text :: Diff


你的文件是CSV文件的事实对于你想要做的事情是无关紧要的,所以回到简单的文件比较。我不知道这个模块将提供什么类型的输出,但我几乎可以肯定它可以通过这种方式进行调整以实现您想要的结果。


- 米勒
Well, of course it''s slow. You''re scanning through a large portion of file2 for every line in file1. This means that your your execute time is relative to the square of the size of the files.

Ignoring your current algorithm for now though, I would suggest that you look into a cpan module to do this for you.

cpan Text::Diff


The fact that your files are CSV files is irrelavent for what you''re trying to do, so just go back to simply file comparing. I don''t know what type of output this module will provide, but I''m almost certainly that it can be adapted in such a way to acheive the results you desire.

- Miller


这篇关于使用perl比较两个csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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