Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: substrings that consist of repeating characters

by wazat (Monk)
on Sep 30, 2020 at 23:47 UTC ( [id://11122384]=note: print w/replies, xml ) Need Help??


in reply to substrings that consist of repeating characters

While I wouldn't recommend it, I didn't see the following approach:

my $string = 'AAATTTAGTTCTTAAGGCTGACATCGGTTTACGTCAGCGTTACCCCCCAAGTTATT +GGGGACTTT'; my %max; $string =~ s[(.)\1*][if ( length($&) > ($max{$1} // 0) ) {$max{$1} = l +ength($&); }]eg; for my $k (sort keys %max) { print"$max{$k} ", $k x $max{$k}, "\n"; }

output

3 AAA 6 CCCCCC 4 GGGG 3 TTT

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-03-29 06:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found