in reply to Finding a pattern in a string
It's not clear what exactly you're after, but my take is that you want to know the offsets within $string where $den occurs. The following code does just that (I've made $string shorter for posting purposes).
my @chars = ('A','D'); my $string = join '', map $chars[ rand @chars ], 1 .. 20; my $den = 'DA'; my @positions; while ( $string =~ /$den/g ) { push @positions, pos( $string ) - length $den; } if ( @positions ) { print "'$den' was found at offsets @positions\n"; } else { print "DA is not present\n\n\n"; } print +(0 .. 9) x 5, "\n"; print "$string\n";
Sample run:
'DA' was found at offsets 2 5 7 10 01234567890123456789012345678901234567890123456789 ADDAADADADDAAAAAAAAA
Notes
|
|---|
| Replies are listed 'Best First'. |
|---|