I have this text (shortened version of my original text):
mytext.txt BAHJSBUBGUCYHAGSBUCAGSUCBASBCYHUBXZCZPZHCUIHAUISHCIUJXZJCBZYAUSGHDYUAGWEBWHBHJASBHJASCXZBUYTRTRTRJFUARGAFGOOPWWKBBCAAAABBXHABSDAUSBCZAAAAAAAAACGAFAXHJBJHXZCXZCCZCXZUCAGSUCBASBCYHUBXZCZPZHCUIHAUISHCIUJXZJCBZYAUSGHDYUAGWEBWHBHJASBHJASCXZBUYHABSDAUSZXHJBRRRRRRJFUABGAFGLLPKWAACAAAABBZJHXZXHJBJHXZXHJBJHXJBJHXZCXZCCZCXZUCAGSAJIJICXZIJUAUUISUSJUSSJSJSJAJCXZXCZTTTTTRJFUABGAFGLOPKWABCAAAABBU
My code is the following, which intends to print all of the matches and then save them into a file as well. But I am not getting any matches while I except there to be at least 10 in my original file.
open(text, "<mytext.txt");
push (@matches,$&) while(<text> =~ m{
([TR]{6}
JFUA
[ABR]{1}
GAFG
( [LOP]{2,3} )
[KW]{2,5}
(??{ $2 =~ tr/LOP/ABC/r })
AAAABB[UXZ]{1})
/g
}x);
print "@matches\n";
my $filename = 'results_matches.txt';
open(my $fh, '>', $filename) or die "Could not open file '$filename' $!";
print $fh "@matches\n";
close $fh;
print "done\n";
I have also tried the following code and this also does not work:
my @matches = <text> =~ m{
([TR]{6}
JFUA
[ABR]{1}
GAFG
( [LOP]{2,3} )
[KW]{2,5}
(??{ $2 =~ tr/LOP/ABC/r })
AAAABB[UXZ]{1})
/g
}x;
print "@matches\n";
I have the following code which successfully prints out only one (the first) result. But it fails to print all of the matches.
if (<text> =~ m{
([TR]{6}
JFUA
[ABR]{1}
GAFG
( [LOP]{2,3} )
[KW]{2,5}
(??{ $2 =~ tr/LOP/ABC/r })
AAAABB[UXZ]{1})
}x) {print "$1\n";}
I have followed the answers in this topic but have not been able to get any of them to work: How can I find all matches to a regular expression in Perl?