Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
perldoc -q substring
perldoc -f pos
perldoc -f index

update: example

use strict; use warnings; my $YBL027W = 'GUAUGUUUAACAGUGAUACUAAAUUUUGAACCUUUCACAAGAUUUAUCUUUAAAU +AUGUUAUGA'; my $seq = shift || 'GUAUG'; my @pos; while( $YBL027W =~ m/\Q$seq\E/gis ){ push @pos, pos($YBL027W) - length( $seq ); } print regex => $/; printf ' \%d0', $_ for 1 .. 8; print $/, ( 0 .. 9 ) x 8, $/; print $YBL027W,$/; my $req = ' ' x length $YBL027W; substr($req, $_, 1, '^') for @pos; print $req, $/; print "@pos $/"; @pos = (); for( my $lindex = index( $YBL027W, $seq); $lindex != -1; $lindex = index( $YBL027W, $seq, $lindex + length $seq) # + length $seq so it matches the m//atch solution # otherwise UUU in UUUU would match twice ( [UUU]U and U[UUU] +) ) { push @pos, $lindex; } print $/, index => $/; printf ' \%d0', $_ for 1 .. 8; print $/, ( 0 .. 9 ) x 8, $/; print $YBL027W,$/; $req = ' ' x length $YBL027W; substr($req, $_, 1, '^') for @pos; print $req, $/; print "@pos $/"; __END__ loose$ perl substring.pl regex \10 \20 \30 \40 \50 \60 \70 + \80 0123456789012345678901234567890123456789012345678901234567890123456789 +0123456789 GUAUGUUUAACAGUGAUACUAAAUUUUGAACCUUUCACAAGAUUUAUCUUUAAAUAUGUUAUGA ^ 0 index \10 \20 \30 \40 \50 \60 \70 + \80 0123456789012345678901234567890123456789012345678901234567890123456789 +0123456789 GUAUGUUUAACAGUGAUACUAAAUUUUGAACCUUUCACAAGAUUUAUCUUUAAAUAUGUUAUGA ^ 0 loose$ perl substring.pl UUUAA regex \10 \20 \30 \40 \50 \60 \70 + \80 0123456789012345678901234567890123456789012345678901234567890123456789 +0123456789 GUAUGUUUAACAGUGAUACUAAAUUUUGAACCUUUCACAAGAUUUAUCUUUAAAUAUGUUAUGA ^ ^ 5 48 index \10 \20 \30 \40 \50 \60 \70 + \80 0123456789012345678901234567890123456789012345678901234567890123456789 +0123456789 GUAUGUUUAACAGUGAUACUAAAUUUUGAACCUUUCACAAGAUUUAUCUUUAAAUAUGUUAUGA ^ ^ 5 48 loose$

MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
** The third rule of perl club is a statement of fact: pod is sexy.


In reply to Re: look for substrings and getting their location by PodMaster
in thread look for substrings and getting their location by wolffm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2024-04-24 22:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found