My suggestion would be to rewrite this code as a state machine. A state machine has one variable with possible values of 0,1,2,3,.... That is the state. Whenever you parse something, for example a line with 'be0.01t' in it, you change the state to reflect where you are in the file. So state 1 might mean "I've just parsed a line with ####.30c, I'm expecting more of them now or blank lines or comments".
You might even draw a simple diagram now with arrows connecting two states, where one can lead to the other and note the condition on the arrow.
The new code would look somewhat like this:
The code will be more wordy but it will be a lot more mantainable and you will be more confident that your program can read whatever is coming at itmy $state=0; #state 0 you expect a card id or comments while ( my $line = <$FILE> ) { if ($state==0) { if ($line=~/.../) { dosemthing; $state=1; } elsif ($line=~/.../) { dosemthingelse; $state=4; else { print "error in datafile"; $state=0; } } elsif ($state==1) { if ($line=~/.../) { ...
In reply to Re: Skipping data on file read
by jethro
in thread Skipping data on file read
by igotlongestname
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |