Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: look for substrings and getting their location

by CombatSquirrel (Hermit)
on May 09, 2004 at 12:08 UTC ( [id://351829]=note: print w/replies, xml ) Need Help??


in reply to look for substrings and getting their location

And, in the spirit of TIMTOWTDI, here's one without RegExes:
#!perl use strict; use warnings; my $seq = 'GUAUGUUUAACAGUGAUACUAAAUUUUGAACCUUUCACAAGAUUUAUCUUUAAAUAUGUUAUGA'; my $search = 'UUUAA'; my $max = length($seq) - length($search); my $i = 0; my @results; while ($i < $max) { $i = index($seq, $search, $i); if ($i == -1) { last; } else { push @results, $i; } ++$i; } print @results . " match(es)\n\n"; print " $seq\n"; for (@results) { printf "%02.2d: %s%s\n", $_, ' ' x $_, $search; }
It might be faster or not ;-).

Hope this helped.
CombatSquirrel.
Entropy is the tendency of everything going to hell.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-26 07:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found