In my previous question in this thread I asked to count the number of occurrences of all permutations with repetitions.
What if I only wanted to not have the count but a binary answer (i.e. 0 or 1) if a specific permutation is in my string? There must be a way to just change the regexp in a minor way.
Up until now I used the suggested solution of:
$n=4;
$str="abababbcad";
%count;
while($str =~ m[(?=([abcd]{$n})).]g){
++$count{ $1};
}
I know I could set
$count{$1}=1
but this is not desirable since I would like to add to the hash the counts of unique occurrences of other strings. For example:
$str1="abad";
$str2="aaab";
$n=2;
should give the following list:
aa 1
ab 2
ad 1
ba 1
Thanks!
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.