Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Keeping track of substituted regions with a while loop

by kschwab (Vicar)
on Nov 15, 2013 at 22:51 UTC ( [id://1062814]=note: print w/replies, xml ) Need Help??


in reply to [SOLVED] Keeping track of substituted regions with a while loop

Based on your sample data, this seems more straightforward, and avoids the issue of substituting something that was already translated. Caveat: I'm guessing based on the sample data, so I may have missed something crucial.

my $protein; # split $rna into groups of 3 characters for ( unpack("(A3)*",$rna)) { if (exists($gencode{$_}) { $protein.=$gencode{$_}; } else { die "No mapping for [$_]\n"; } }

Replies are listed 'Best First'.
Re^2: Keeping track of substituted regions with a while loop
by kschwab (Vicar) on Nov 15, 2013 at 22:59 UTC
    Missed a paren...
    for ( unpack("(A3)*",$rna)) { if (exists($gencode{$_})) { $protein.=$gencode{$_}; } else { die "No mapping for [$_]\n"; } }
Re^2: Keeping track of substituted regions with a while loop
by enderk (Novice) on Nov 16, 2013 at 13:21 UTC

    Hi kschwab, thanks for your reply. You're absolutely right, that is another way of solving this problem (by sequentially appending the one-letter codes to a new string instead of substituting an existing string) and it is similar to the "alternative" method I described in my original post.

    However, I was not looking so much into getting the right answer as rather trying to learn more about how to use regexes, combined with a while loop, in this situation. Is there an "easy" way for Perl to keep track of the position it is in, as it moves along a string in a while loop, or would that be an overkill to do, considering there are easier options available?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-19 13:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found