in reply to Avoid run-time checking
Hello bagyi,
This sounds like a textbook example of a problem waiting for an OO solution. Make a Record class containing a factory-pattern constructor along with the various methods applicable to a record. Then create a subclass for each record type — e.g. Record_Big_Endian and Record_Little_Endian — which inherit from the parent Record class. Override Record methods in these subclasses if and when necessary. This will give you an API which can be used without explicit reference to the endianness of the records being processed:
use Record; ... my $endianness = get_first_record($file); # or better: put this into + the Record::new class method my $record = Record::new($endianness); # returns either a Record_ +Little_Endian or a Record_Big_Endian object $record->unpack(); # unpacks the record in a +way that is endian-transparent ...
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Avoid run-time checking
by bagyi (Acolyte) on Sep 12, 2015 at 08:30 UTC | |
by Anonymous Monk on Sep 12, 2015 at 09:08 UTC |