Probably someone will tell you the bug, but that still makes this code hard to read, understand and maintain. Especially the multiple reads from $FILE are errorprone. And it really gets dark when your input file has an error in it.

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:

my $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=~/.../) { ...
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 it


In reply to Re: Skipping data on file read by jethro
in thread Skipping data on file read by igotlongestname

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.