hi
I need to find the complement of this:
$_ = 'aaaaabaaabaaabacaaaa';
while( /([a][a][a][a])/gc){
next if pos()%4 != 0;
my $b_pos = (pos()/4)-1;
print " aaaa at :$b_pos\n";
}
That is, a suite of 4 caracters that is not 'aaaa'.
The following doesn't work
$_ = 'aaaaabaaabaaabacaaaa';
while( /([^a][^a][^a][^a])/gc){
my $b_pos = (pos()/4)-1;
print "not a at :$b_pos\n";
}
Of course I can do this
$_ = 'aaaaabaaabaaabacaaaa';
while( /(....)/gc){
next if $1 eq 'aaaa';
my $b_pos = (pos()/4)-1;
print "$1 a at :$b_pos\n";
}
Isn't there a more direct way?
To clarify the expected result, I need to find all 4 letter suite that are not 'aaaa' as well as there position.
1st code outputs
aaaa at :0
aaaa at :4
2nd code should output
not aaaa at :1
not aaaa at :2
not aaaa at :3
3rd code output, is what I'm looking for
abaa at :1
abaa at :2
abac at :3
I understand I haven't been clear enough, please receive my appologies.
What I'm trying to acheive is like dividing a string in groups of 4 letters, getting the value and position of the groups that doesn't match the pattern.
My third code gives me the expected result. It reads the string 4 letter at the time and process the those that aren't 'aaaa'.
I also found out, thank to all of your suggestions, that my first code doesn't work as expected, it should skip if pos()%4 != 0, which would mean that the pattern spans over two groups of 4. I corrected the code.
Against all expectations, from me and others, the following doesn't ouput anything at all
/[^a]{4}/
I should probably stick with my 3rd code.