in reply to Re^3: Regex KungFu help needed
in thread Regex KungFu help needed
Nice, ++
If you don't need to refer to the pattern again you can reduce that to a single step with the uncompiled pattern as key and count as value.
$ perl -Mstrict -wle ' > my $seq = q{GGGGGGGAGAAAAAAAAAAAAAAAGAAGGA}; > my %pats = map { > $_, scalar( () = $seq =~ m{(?=\Q$_\E)}g ); > } qw{ AAAAA GGGGG GGAGA GAAGG }; > print qq{$_: $pats{ $_ }} for sort keys %pats;' AAAAA: 11 GAAGG: 1 GGAGA: 1 GGGGG: 3 $
I expect some Monks could golf that down to seven bytes and a nybble :-)
Cheers,
JohnGG
Update: Extra parentheses inside the map were un-necessary, removed!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Regex KungFu help needed
by grizzley (Chaplain) on Oct 05, 2009 at 07:17 UTC |