in reply to Parse File With Sub While Loops
Basically, the first if is true only if we've already found a line containing only FH, but haven't yet found a line containing FT. The second if is true when we've found a BH line, but haven't yet found either another BH line or an FT line.while (<MYFILE>) { if (/^FH$/ .. /^FT$/) { # $_ is a line within FH and FT lines # including the delimiting lines } if (/^BH$/ ... /^BH$|^FT$/) { # $_ is a line between BH lines, or between # a BH and FT line }
Hope this helps,
-- Bird
Oh, the reason the second if uses three dots (...) is because the two dot version can become false in the same check that it became true. Essentially, if you use the two dot version to match a block which uses the same start and end delimiter, you may only end up processing the first line of the block (which would be the delimiter, in this case).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Parse File With Sub While Loops
by bronto (Priest) on Sep 17, 2002 at 10:46 UTC |