Michael S. Robeson II wrote:
I came across some code on the internet that looks like this (this
is only part of the script):

while (<align>) {
      $line=$_;
        if ($line=~/^>(.+)/) {
                if ($seq) {
                        $pro{$name}=$seq;
#print "SEQ:\n$pro\n\n";
                }
                $name=$1;
            $name=~s/\s//g;
        push @names, $name;
#print "$name\n";
                $k++;
                $seq="";
        }
        else {
                chomp $line;
                $seq.=$line;
        }
}

I am having trouble figuring out how the nested if statements
work (i.e. what is the order of operation etc...) and their
associated else statements.

That illustrates the importance of indenting the code in a way that makes sense:


    while (<align>) {
        $line=$_;
        if ($line=~/^>(.+)/) {
            if ($seq) {
                $pro{$name}=$seq;
                #print "SEQ:\n$pro\n\n";
            }
            $name=$1;
            $name=~s/\s//g;
            push @names, $name;
            #print "$name\n";
            $k++;
            $seq="";
        } else {
            chomp $line;
            $seq.=$line;
        }
    }

Quite a difference, isn't it?

--
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>




Reply via email to