Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
We don't bite newbies here... much
 
PerlMonks  

Re: Regex: finding all possible substrings

by tobyink (Prior)
on Jun 01, 2012 at 14:48 UTC ( #973793=note: print w/ replies, xml ) Need Help??


in reply to Regex: finding all possible substrings

use strict; use Data::Dumper; use List::MapMulti 'iterator_multi'; my @userDefined = qw(AAA AAC ACA CAA); my $string = 'AAAAA AAACACA CAACAAA'; my %results = map { $_ => 0; } @userDefined; my $iter = iterator_multi [0..length($string)-1], [1..length($string)] +; while (my ($start, $end) = $iter->()) { next unless $end > $start; my $substr = substr $string, $start, ($end - $start); $results{$substr}++ if exists $results{$substr}; } print Dumper \%results;
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'


Comment on Re: Regex: finding all possible substrings
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://973793]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (18)
As of 2013-05-21 08:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (431 votes), past polls