Hi,

I'm parsing through a file and using multiple "if" and "while(<filename>)" statements to match against the file. When I do one "if" statement, it skips over the second, and so on. Second "if" only works when I restate the "while" and so on. Is there a better way to parse through a file and still match? Is there a way I can use multiple "if"? Below is the code (by the way, some lines are commented out because I was debugging. So they were originally not commented out):

if(/scanchain/){ $flag0 = 1; #while($flag0){ print "in scanchain while loop\n"; $flag1 = 1; #while($flag1){ if (/(\s+)chain(\d+)_chain \[/){ print "Why hello there?\n"; $scanchain_chain_no = $2; #$flag = 1; #while($flag){ #for($t=0; $t<=$Chain_No_size; $t++){ #print "in for loop\n"; #while(<WGL>){ #print "Coo\n"; #if($Chain_No[$t] eq $scanchain_chain_ +no){ #print "too\n"; #print "$Chain_No[$t]\n"; #my $Input_Pin = <WGL>; + #$Input_Pin =~ tr/"//d; + #$Input_Pin =~ tr/,//d; #$Input_Pin =~ tr/ //d; + #print "Chain $Chain_No[$t] Input Pin += $Input_Pin\n"; #while(<WGL>){ #if(/(\s+)"(.*)"/){ #$quotes = $2; # foreach ($quotes){ # push @Quotes, $quotes;} #} #else{ last; } #} #$Output_Pin=$Quotes[-1]; #print "Chain $Chain_No[$t] Output Pin + = $Output_Pin\n\n"; #} #next; #} #} #next; #} } #} #} }

In reply to Nested if and while statements by crisa89

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.