"Paul Archer" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Thanks a lot! This is just what I was looking for in your first example.
> (The second example won't do me as much good, as I need to consider
> characters that haven't changed inside of a string of characters that
> have--but it's still a good reference.)
>
> Thanks again,

No prob, glad to be of help.

Rob

>
> paul
>
>
> 10:11am, Rob Anderson wrote:
>
> > > If anyone can offer general improvements to that approach, that'd be
> > > great--but what I'm really interested in is finding the first element
that
> > > differs, and maybe the last as well. If there were any easy way to
find
> > > that, say, the first character that differs is at position 120, and
the
> > last
> > > character that differs is at position 135, then I only have to loop
> > through
> > > 15 characters, not 160.
> >
> > Probably the quickest way to do this in perl is as follows....
> >
> > ----------------------------------------
> > #!/perl -w
> > use strict;
> > my $string1 = "The quick brown fox.";
> > my $string2 = "The Kuick brUwn fox.";
> >
> > my $string_xor = ("$string1" ^ "$string2");
> >
> > $string_xor =~ /^(\0*)/;
> > print "Number of equal bytes at the front of the string = " . length($1)
.
> > "\n";
> > $string_xor =~ /(\0*)$/;
> > print "Number of equal bytes at the end of the string = " . length($1) .
> > "\n";
> > ----------------------------------------
> >
> > the xor op (^) will return a string, every matching byte of which will
be
> > null, every mismatching byte will have some bit (literaly) set.
> >
> > so the all first regex does is match the all the null bytes it can find
from
> > the front of the string, the length of the string is equivalent to the
> > number of identical chars at the front.
> > The second regex is the same, just working from the end.
> >
> > You could extend this and translate all the non-null values to something
you
> > could then search for that value with index. This would give you the
> > positions of all the bytes that were different...
> >
> > my $string_xor = ("$string1" ^ "$string2");
> > my $pos = 0;
> > while ( ($pos = index($string_xor, 'X', $pos)) != -1) {
> >    print "==> $pos\n";
> >    $pos++;
> > }
> >
> > Hope this helps,
> >
> > Rob
> >
> > >
> > > TIA,
> > >
> > > paul
> > >
> > >
> > > ---------------------------------------------------------------------
> > > On the side of the software box, in the "System Requirements" section,
> > > it said "Requires Windows 95 or better".  So I installed Linux.
> > > ---------------------------------------------------------------------
> >
> >
> >
>
> -----------------------------------------------------
> "Somebody did say Swedish porn, there--
> but someone always does..."
> --Clive Anderson, host of "Whose Line Is It, Anyway",
> after asking the audience for movie suggestions
> -----------------------------------------------------



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to