in reply to Skipping data on file read
I like to write my parsing loops so that I only read lines in one place - like in the outer while statement. Then I only have to check for EOF in one place.$line = <$FILE>; until ( $line =~ /^c/ or $line =~ /^mt?\d+/ ) { ... $line = <$FILE>; }
Also, here's a simpler way to look at the problem. You have three kinds of lines:
Now you just have to work out what to do in each of the three cases. My suggestion is to create a variable to represent the current m-block being recognized. The actions for each type of line would go something like this:while (<$FILE>) { if (m/^m/) { ... } elsif (m/^\s/) { ... } elsif (m/^c/) { ... } else { die "whoops - didn't expect: $_" } }
|
|---|