I have two strings to compare.
- String 1 consists of a mix of 3 characters, a, b & c. Eg. AABCBAABCCCCAB
- String 2 consists of a mix pf 2 characters; a & b.Eg. AABABAABABABAB
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.
Update2: Solution
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
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
In the absence of evidence, opinion is indistinguishable from prejudice.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.