Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing 2 files using perl

Status
Not open for further replies.

mark077916

Programmer
Feb 22, 2011
1
0
0
Guys,

I'm a total newbie to perl and I need to know how to go about comparing 2 seperate files using perl, to ascertain if the files are identical or if there are changes.

Can you point me in the right direction of the right way to do this?

Any guidance / tips would be immensely appreciated.

Regards

Mark
 
Unless you have a specific reason to use perl for this task (like you want to learn it, for example), why not just use diff?

If you do want to learn perl, then as the saying goes "I wouldn't start from here...". A naive comparison program is easy enough, if the records of both files are sorted, but the reality of file comparison is quite a bit harder than that - especially if records have been inserted or deleted. How far should the program look ahead to re-sync after the inserts, or to work out how many records have been deleted?

diff does all this for you, and you don't have to write it...

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top