in reply to Storage of proteins from diferent ORF

Edit: Looks like kennethk also rewrote your code in almost the same way as I was adding my last part, so it must be the right way to do it! :P

Edit2: kennethk pointed out to me that my code is incrementing by three positions when there is an unknown codon, but yours only increments by one position. Is this by design? It seems to me like you would want to move on to the next codon regardless of there being a match or mismatch.

First, your code would be much more simple if you had your codon table in a hash and just looked up the codon in the hash to get the amino acid. Before you entered the loop, you would define the table:

my %codon_table = ( 'TTT' => 'F', 'TTC' => 'F', 'TTA' => 'L', 'TTG' => 'L', 'CTT' => 'L', 'CTC' => 'L', 'CTA' => 'L', 'CTG' => 'L', # AND SO ON );

Second, I'm not really familiar with this usage:

@marcos=<,$protein>;

I think what you want instead of this line is:

push @marcos, $protein;

Then if you move your last little loop outside of the main loop, I think it should behave the way you expect. Here is a simplified version of that last loop:

print "La secuencia $c es: $_\n\n" for @marcos;

Third, I suspect that you aren't using use strict; use warnings;... Use these!

I've combined all of these suggestions and made a few more changes to rewrite your code as:

my %codon_table = ( 'TTT' => 'F', 'TTC' => 'F', 'TTA' => 'L', 'TTG' => 'L', 'CTT' => 'L', 'CTC' => 'L', 'CTA' => 'L', 'CTG' => 'L', # AND SO ON ); my @marcos; for my $reading_frame ( 0 .. 2 ) { my $position = $reading_frame; while ( $position < length($DNA) - 2 ) { my $codon = substr( $DNA, $position, 3 ); my $amino_acid = $codon_table{$codon}; if ( defined $amino_acid ) { $protein = $protein . $amino_acid; } else { $protein .= "x"; } $position += 3; } push @marcos, $protein; } print "La secuencia $reading_frame es: $_\n\n" for @marcos;