[Date Prev][Date Next][Thread Prev][Thread Next]
[Search]
[Date Index]
[Thread Index]
Re: [FWP] Comparing strings the hard way
On Oct 26, Ariel Scolnicov said:
>Perl's string operations are very powerful, but sometimes they're just
>not good enough. Case in point: I have 2 strings of the same length.
>I need to know which portions of them are equal, and which are not.
>
> @l = map { length } split /[^\c@]/, $a^$b
>
>gives me the lengths of consecutive equal portions of $a and $b.
This is somewhat related to the greatest substring problem (someone at
YAPC 19100 gave a talk on it).
# greatest_common_substring
sub gcs {
substr($_[0], 0, length(split /[^\0]/, $_[0]^$_[1], 2)[0]);
}
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
==== Want to unsubscribe from Fun With Perl? Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
==== unsubscribe