How to change the comparsion criteria of diff?

M

Michael

Hi all:
I'm meeting the problem with diff methods in Perl.
I am comparing two files, one containing regular-expression string
texts, and the other doesn't. what I need to do is to find the
difference between EXCEPT FOR when regular expression matches with the
other's corresponding text, which is shown as below,
For example:
A.txt: Hello every one! I like .* languages very much!
B.txt: Hello every one! I like Perl Languages very much!
The regexp ".*" in A.txt is used to match any string in B.txt as the
normal regular expression does. Here A.txt and B.txt are considered
equal. But the general diff method would consider them as difference
with line-by-line text comparison. And if there are different, I want
the output with same behavior as in the UNIX.

I searched into the modules of Perl, like Text::Diff, Algorithm::Diff,
but didn't get any idea of it. I saw that one comparison method can be
passed into Algorithm::Diff as the new comparison criteria in the doc
online, but failed after trying. Could any one give a simple example
showing this feature?
my (@seq1, @seq2) = (<FH1>, <FH2>);
diff(\@seq1, \@seq2, $comparison_function);
I don't know what is the rules of designing this $comparison_function?

If there is some other way to do this, please kindly tell me, thanks
very much!
 
M

Michael Yang

Hi all:
I'm meeting the problem with diff methods in Perl.
I am comparing two files, one containing regular-expression string
texts, and the other doesn't. what I need to do is to find the
difference between EXCEPT FOR when regular expression matches with the
other's corresponding text, which is shown as below,
For example:
A.txt: Hello every one! I like .* languages very much!
B.txt: Hello every one! I like Perl Languages very much!
The regexp ".*" in A.txt is used to match any string in B.txt as the
normal regular expression does. Here A.txt and B.txt are considered
equal. But the general diff method would consider them as difference
with line-by-line text comparison. And if there are different, I want
the output with same behavior as in the UNIX.

I searched into the modules of Perl, like Text::Diff, Algorithm::Diff,
but didn't get any idea of it. I saw that one comparison method can be
passed into Algorithm::Diff as the new comparison criteria in the doc
online, but failed after trying. Could any one give a simple example
showing this feature?
my (@seq1, @seq2) = (<FH1>, <FH2>);
diff(\@seq1, \@seq2, $comparison_function);
I don't know what is the rules of designing this $comparison_function?

If there is some other way to do this, please kindly tell me, thanks
very much!

To be more clearly on this question:
I need the script to ignore the text differences when the regex in one
file matches the corresponding part in the other. Thus I need to ask
the diff utility to compare two files with the new rules of regex as
shown above, which could be defined in a comparison function by user
self.
 
M

Michael Yang

To be more clearly on this question:
I need the script to ignore the text differences when the regex in one
file matches the corresponding part in the other. Thus I need to ask
the diff utility to compare two files with the new rules of regex as
shown above, which could be defined in a comparison function by user
self.

Is there anyone could help me on this diff implementation?

It's really appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top