BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:
I have two strings to compare.
I need to determine if string 2 contains As everywhere there is an A in string 1; and Bs wherever string 1 contains Bs. I don't care what string 2 contains where string 1 contains Cs.
All I need is a boolean result whether string 2 'matches' string 1. (The above example is a 'match'.)
If it helps, the choice of the 3 characters used is open to change.
The strings can be quite long and there are lots of string 2s to be compared against each string 1; so I'd rather avoid a byte by byte (at the Perl level) comparison.
I think it ought to be possible to get my boolean using some combination of byte-wise boolean string ops; but I haven't hit on which?
Update: The above two samples match because:
AABCBAABCCCCAB AABABAABABABAB AAB BAAB AB ## I don't care what's in string 2 where there is a C +in string 1.
Solved it with:
$ab = "AABABAABABABAB";; $abmatch = "AABABAABABABAB";; print +(( $abc & $abmatch ) eq $abmatch) ? 'yes' : 'no';; yes $abnomatch = "ABBABAABABABAB";; print +(( $abc & $abnomatch ) eq $abmatch) ? 'yes' : 'no';; no
|
|---|