We don't bite newbies here... much | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
G'day FIJI42, I wrote in "Re: Identifying Overlapping Matches in Nucleotide Sequence": "Biological data are typically huge. For reasons of efficiency, when dealing with this type of data, you should choose a fast solution over a slower one. Perl's string handling functions ... are measurably faster than regexes ..." Here's a solution that uses the string handling functions length and substr (no regexes are used at all):
Output:
Notes: My %code is just a subset of your %genetic_code: it only has the data required for your example sequences. You will still need all the data; you can save yourself some typing by omitting the 128 single quotes around all the keys. You can use state within your subroutine (if you're using Perl version 5.10 or higher); although, be aware that limits the scope. I often find that when I write code like:
instead of like:
I subsequently find I need to share $static_var with another routine. This requires a major rewrite which ends up looking very much like the version with BEGIN:
Just having to add 'sub g { ... }' to existing code is a lot less work and a lot less error-prone. How you choose to do it is up to you: I'm only providing advice of possible pitfalls based on my experience. — Ken In reply to Re: Translation Substring Error
by kcott
|
|