crisa89 has asked for the wisdom of the Perl Monks concerning the following question:
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; #} } #} #} }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Nested if and while statements
by AppleFritter (Vicar) on Jun 23, 2014 at 22:36 UTC | |
|
Re: Nested if and while statements
by hippo (Archbishop) on Jun 23, 2014 at 22:34 UTC | |
|
Re: Nested if and while statements
by Laurent_R (Canon) on Jun 24, 2014 at 06:36 UTC |