How to change the comparsion criteria of diff?

Discussion in 'Perl Misc' started by Michael, May 8, 2007.

  1. Michael

    Michael Guest

    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!
     
    Michael, May 8, 2007
    #1
    1. Advertising

  2. Michael

    Michael Yang Guest

    On May 8, 11:18 am, Michael <> wrote:
    > 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.
     
    Michael Yang, May 8, 2007
    #2
    1. Advertising

  3. Michael

    Michael Yang Guest

    On May 8, 2:47 pm, Michael Yang <> wrote:
    > On May 8, 11:18 am, Michael <> wrote:
    >
    >
    >
    > > 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.


    Is there anyone could help me on this diff implementation?

    It's really appreciated.
     
    Michael Yang, May 9, 2007
    #3
  4. Michael

    Michael Yang Guest

    On May 9, 10:02 am, Michael Yang <> wrote:
    > On May 8, 2:47 pm, Michael Yang <> wrote:
    >
    >
    >
    > > On May 8, 11:18 am, Michael <> wrote:

    >
    > > > 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.

    >
    > Is there anyone could help me on this diff implementation?
    >
    > It's really appreciated.


    no answer yet~~ :(
     
    Michael Yang, May 11, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cyril Vi?ville

    diff Process under diff users

    Cyril Vi?ville, Jun 29, 2004, in forum: Perl
    Replies:
    1
    Views:
    523
    Joe Smith
    Jun 29, 2004
  2. Berrucho
    Replies:
    2
    Views:
    668
    Infant Newbie
    Dec 5, 2003
  3. A Traveler

    Diff CSS styles for diff INPUT TYPE='s?

    A Traveler, Aug 31, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    4,958
    Steve Fulton
    Aug 31, 2004
  4. c676228

    strange result of Date value comparsion

    c676228, Dec 9, 2008, in forum: ASP General
    Replies:
    6
    Views:
    156
    Adrienne Boswell
    Dec 13, 2008
  5. Austin Ziegler

    [ANN] Diff::LCS 1.1.0, Diff::LCS 1.0.4

    Austin Ziegler, Aug 8, 2004, in forum: Ruby
    Replies:
    3
    Views:
    207
    Austin Ziegler
    Aug 9, 2004
Loading...

Share This Page