Re: nested "if"

From: Michael S. Robeson II (popgen23_at_mac.com)
Date: 07/04/04

  • Next message: Michael S. Robeson II: "Re: nested "if""
    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
    >


  • Next message: Michael S. Robeson II: "Re: nested "if""

    Relevant Pages

    • Re: Can inner join replace multiple loop selects?
      ... The only wrinkle is not incrementing between R and L ... So somehow I need to read the entire group, set a boolean bHaveL and then ... Loop through each of those and set bHaveL variable for each ...
      (comp.databases.ms-access)
    • Re: Reading binary files of irregular format with TMemoryStream
      ... One thing that troubles me is the field data itself. ... if I am told that a field is 4 bytes in length and somehow it gets ... If I go in with a for/next loop and read 4 bytes, ... I'm getting a copy of a corrupted file sent to me so I can inspect it a ...
      (comp.lang.pascal.delphi.misc)
    • User Defined Class : How to expose a collection of properties?
      ... Could I use the FOR EACH construct to loop through the properties ... (grin). ... Prev by Date: ...
      (microsoft.public.scripting.vbscript)
    • RE: Use DataGrid To Add New Records
      ... I somehow have to loop through the dataset to get the columns ... and then build the columns in the datagrid based on those columns. ... snippet would be helpful. ...
      (microsoft.public.dotnet.framework.aspnet.webcontrols)
    • Re: Array Initialization
      ... Gunnar Hjalmarsson wrote: ... time through the loop. ... The assignment happens when the code is run so it is re-run every time. ...
      (perl.beginners)