Michael S. Robeson II wrote:
Ok, well I think I can see the forest but I have little idea as to
what is actually going on here. I spent a few hours looking things
up and I have a general sense of what is actually occurring but I
am getting lost in the details that were posted in the last digest.
Well, before an attempt to explain and/or point you to the applicable
docs, I'd like to change my mind once again. :) This is my latest
idea:
my %hash3;
for ( keys %hash1 ) {
my $dna = $hash2{$_};
for my $aa ( split //, $hash1{$_} ) {
$hash3{$_} .= $aa eq '-' ? '---' : substr $dna,0,3,'';
}
}
I'll assume that you don't have a problem with the outer loop, that
simply iterates over the hash keys. As a first step in each iteration
I copy the DNA sequence to the $dna variable, so as to not destroying
%hash2.
Over to the 'tricky' part. The inner loop iterates over each character
in the amino-acid sequence data, and respective character is assigned
to $aa. For that I use the split() function:
http://www.perldoc.com/perl5.8.4/pod/func/split.html
$hash3{$_} .= $aa eq '-' ? '---' : substr $hash2{$_},0,3,'';
This is something new to me. I think I follow your use of the ?:
pattern feature. However, none of the perl books I have discuss
it's use in this fashion.
That sounds strange to me, because that's how it should be used...
Read about the conditional operator in
http://www.perldoc.com/perl5.8.4/pod/perlop.html
OTOH, that notation is basically the same as:
if ( $aa eq '-' ) {
$hash3{$_} .= '---';
} else {
$hash3{$_} .= substr $dna,0,3,'';
}
which is a little more intuitive (at least I think it is).
So, as far as I can tell, you are saying: "hey, if you find '-' in
$aa then append a '---' in $hash3, otherwise append the next three
DNA letters".
Precisely.
However, I do not understand the syntax of how perl is actually
doing this.
Hopefully the if/else statement makes it easier to grasp, and the '.='
operator is used just for appending something to a string.
Finally we have my use of the substr() function.
http://www.perldoc.com/perl5.8.4/pod/func/substr.html
It returns the first three characters in $dna, and since I also pass
the null string as the fourth argument, it changes the content of $dna
at the same time, i.e. it replaces the first three characters with
nothing.
HTH. If you need further explanations, you'll have to ask specific
questions.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>