bagyi has asked for the wisdom of the Perl Monks concerning the following question:
sub record_foo # parse foo type record sub record_bar # parse bar type record sub record_boo # parse boo type record sub record_xxx { if($endian eq 'little') { unpack("v3A*" ...); } elsif ($endian eq 'big') { unpack("n3A*"...); }
I would like to avoid these test of endianness in each of sub-routines while maintaining clarity of code and ease to maintain.
So far, the only idea I have came up - create 2 tables of unpack template, one for big and one for little and select once after determining endianness.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Avoid run-time checking
by Athanasius (Archbishop) on Sep 12, 2015 at 07:48 UTC | |
by bagyi (Acolyte) on Sep 12, 2015 at 08:30 UTC | |
by Anonymous Monk on Sep 12, 2015 at 09:08 UTC | |
|
Re: Avoid run-time checking
by Anonymous Monk on Sep 12, 2015 at 07:10 UTC | |
by bagyi (Acolyte) on Sep 12, 2015 at 07:34 UTC | |
by Anonymous Monk on Sep 12, 2015 at 09:01 UTC | |
|
Re: Avoid run-time checking
by Laurent_R (Canon) on Sep 12, 2015 at 09:01 UTC |