in reply to Re: Reading binary file in perl having records of different length
in thread Reading binary file in perl having records of different length
Ack! Learn a lesson from my own mistake and use constants instead of strings for $expect (note the typo "eyecater"). I was being lazy :-(
Also, the pseudocode doesn't handle the case of the file not beginning with "==", which you could handle in the first else like so: else { die "expected eyecatcher" unless $expect eq 'eyecatcher' }.
If the logic starts getting too complex, get a little more verbose and break the first if up: if ($expect eq 'eyecatcher') {} elsif ($expect eq 'eyecatcher_after_record') {} and so on. Always cover all branches; at the very least throw a else { die "unexpected" } on there during development.
And choosing the right names for your states helps a lot. For example, "eyecatcher" might be better named "first_eyecatcher".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Reading binary file in perl having records of different length
by jaypal (Beadle) on Jun 17, 2014 at 02:06 UTC | |
by Anonymous Monk on Jun 17, 2014 at 13:48 UTC | |
by jaypal (Beadle) on Jun 17, 2014 at 15:43 UTC |