Re: nested "if"
From: Michael S. Robeson II (popgen23_at_mac.com)
Date: 07/04/04
- Previous message: Michael S. Robeson II: "Re: nested "if""
- In reply to: Michael S. Robeson II: "Re: nested "if""
- Next in thread: Michael S. Robeson II: "Re: nested "if""
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 3 Jul 2004 22:16:34 -0400 To: beginners@perl.org
No, your post was not in the last e-mail digest I received, unless I
missed it somehow? But the link you provided seems to clear things up
for me. So, it's not about the order of operation but the timing of
when the variables actually get defined.
That is, during the beginning of the loop since the values are not
defined then they are ignored. When the loop proceeds again these
values (at this point) are now defined because of the previous
iteration of the loop has set the values from the else statement?
-Mike
On Jul 2, 2004, at 10:25 PM, Michael S. Robeson II wrote:
> Well yeah, the indentation makes it much more clearer. However, this
> does not help me understand how the nested "if" statements are
> working. Which of the two "if" statements gets evaluated first? I am
> trying to figure out "in english" what the "if" statements are
> actually doing. Is it saying:
>
> "If a line begins with ">bla-bla" and if $seq (which appears no
> where else in the code other than " $seq="" ") exists assign it to the
> hash "pro" with the name "bla-bla"."
>
> So my question is how does the inner if statement work when seq="" is
> out side that "if" statement?
>
> Is the outer "if" statement evaluated first then the inner? Because
> how does the inner "if" statement know what "$seq" is?
>
> I am probably not making any sense but I am trying to figure out
> mechanically how the perl interpreter knows what to do in the context
> of the nested if statements.
>
> -Thanks
> -Mike
>
> Gunnar Hjalmarsson wrote:
> 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
>
- Previous message: Michael S. Robeson II: "Re: nested "if""
- In reply to: Michael S. Robeson II: "Re: nested "if""
- Next in thread: Michael S. Robeson II: "Re: nested "if""
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|