Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hello fellow Monks!
I have 2 strings, namely:
I want to know how many letters do they share in common. The "traditional" way that I'm thinking of is:
1) Split $first, split $second
2) Foreach letter in @split_first array, see if, in the same position in the array @split_second you have the same letter
3)Count the times you get success
Is there something quicker than that?
I just need the number of positions in the arrays (they always have the same number of letters), that the have the same letter.
Thanks!
I have 2 strings, namely:
$first= "AAAAXXXXAAAAXXXXXXXXXXXAAAA"; $second="AXXXAXXAAXXXXXAAAAXXXXXAAAA";
I want to know how many letters do they share in common. The "traditional" way that I'm thinking of is:
1) Split $first, split $second
2) Foreach letter in @split_first array, see if, in the same position in the array @split_second you have the same letter
3)Count the times you get success
Is there something quicker than that?
I just need the number of positions in the arrays (they always have the same number of letters), that the have the same letter.
Thanks!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Quicker way to compare these 2 strings?
by TimToady (Parson) on May 19, 2010 at 00:57 UTC | |
Re: Quicker way to compare these 2 strings?
by cormanaz (Deacon) on May 19, 2010 at 00:14 UTC | |
by toolic (Bishop) on May 19, 2010 at 00:29 UTC | |
by Anonymous Monk on May 19, 2010 at 00:29 UTC |
Back to
Seekers of Perl Wisdom