gzayzay has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I am trying to work on a project in wish I compare to files to determine their difference. However, I am have problem performing this task. What I want to do is to give the name of two text file that I almost identical to my program. Let the program open the two files and compare them to see if they are different. Example;

__FILE1__ Life ::= SEQUENCE{ eat eating drink drinking smoke smoking run CHOICE { fast faster slow slower } } Dave :: = CHOICE { club clubing bat batting } __FILE2__ Life ::= SEQUENCE{ eat eating drink drinking dummy smoking run CHOICE { fast faster slow slower } } Dave ::= CHOICE { club clubing bat batting }
Given to two sample files above, you will observe that "dummy" in file2 is what cause the two files to be different. By using dummy next to smoking, this implies that I know longer want to use "smoke" as a sequence of LIFE. My problem is that, instead of getting ride of smoke completely, I want to concatenate dummy with smoke i.e (dummy smoke smoking) in File2. Note that every definition starts with ::= and ends with a curely brace.

Could any monk kindly help me figure out how to do the files comparison and replacement?

Thanks for your assistance.

Edman

Replies are listed 'Best First'.
Re: Comparing two files
by philcrow (Priest) on Jun 13, 2006 at 13:27 UTC
    If you don't want to roll your own, you could use one of these from cpan: Text::Diff or Test::Files.

    Phil

Re: Comparing two files
by jesuashok (Curate) on Jun 13, 2006 at 12:55 UTC
    Hi

    Refer Comparing lines of multiple files. The specified node contains a detailed perl code to compare multiple files. use the same code with minimal modification as per your requirement.

    "Keep pouring your ideas"