Hello monks!
I have a question:
Say you have the strings:
$a="ABCDABCDXBCDABCXABCDXXCDABXD";
$b="ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD";
If in $a there were no X's, then with a pattern match you would say that $b includes $a. I need to write a pattern match to "ignore" other characters in $a if they are X, but DO NOT erase them. What I mean is that, in the position of X in $a, you could have A, B, C or D, does not matter. I tried the following but did not work:
$a="ABCDABCDXBCDABCXABCDXXCDABXD";
$b="ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD";
@split_initial=split(//, $a);
for ($i=0; $i<=$#split_initial; $i++)
{
if($split_initial[$i] ne 'A' && $split_initial[$i] ne 'B' && $spli
+t_initial[$i] ne 'C' && $split_initial[$i] ne 'D')
{
$split_initial[$i]="*";
}
$seq_final=join('', @split_initial);
}
if ($b=~/$seq_final/) {print "OK\n";}
I somehow try to insert artificially, the wildcharacter * in $a, so as to "ignore" what's in position of X (because it can be anything between A,B,C or D -it doesn't matter which one) when it searches $b for the presence of $a..
How can I write this pattern match correctly?
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.