The bulk of this is split / (...). But at the end of this, you will have your position and entry data.
my @expected_triplets = qw<aaa bbb ccc>; my $data_string = 'fjeidoaaaivtrxxcccfznaaauitbbbfzjasdjfncccftjtjqznnjgjaaajeitjgbbblafjan' ; my $place = 0; my @triplets = grep { length } split /(...)/, $data_string; my %occurrence_for = map { $_, [] } @expected_triplets; foreach my $i ( 0..@triplets ) { my $triplet = $triplets[$i]; push( @{$occurrence_for{$triplet}}, $i ) if exists $occurrence_for{$triplet}; }
Or for a simple regex calculation (it uses Experimental (?? {}))
my ( $count, %count ); my $data_string = 'fjeidoaaaivtrxxcccfznaaauitbbbfzjasdjfncccftjtjqznnjgjaaajeitjgbbblafjan' ; $data_string =~ m/(aaa|bbb|ccc)(??{ $count++; $count{$^N}++ })/g;
Axeman
source share