in reply to Re: Avoid run-time checking
in thread Avoid run-time checking

>>Are the files ever mixed endianness? Where does $endian come from , how is endianness determined?

No. The endianness is fixed. it is specified in first record of file. Using table approach seems viable, but I don't like to separate subroutine and template string in different places if possible.

Replies are listed 'Best First'.
Re^3: Avoid run-time checking
by Anonymous Monk on Sep 12, 2015 at 09:01 UTC

    Using table approach seems viable, but I don't like to separate subroutine and template string in different places if possible.

    :) All approaches are viable, it will always come down to your prejudice/bias/choice :D

    so type up a few 1-3 subs of each and then compare/contrast what you like about each

    my %templates; $templates{big}{foo} = 'v3A*'; $templates{lil}{foo} = 'n3A*'; $templates{big}{bar} = 'v2A*'; $templates{lil}{bar} = 'n2A*'; sub record_foo { my( $end, ... ) = ; my @res = unpack $templates{$end}{foo}, ...; ...; } sub record_bar { my( $end, ... ) = ; my @res = unpack $templates{$end}{foo}, ...; ...; } %templates = ( big => { bar => "v2A*", foo => "v3A*", }, lil => { bar => "n2A*", foo => "n3A*", }, ); sub record_foo { my( $big, ... ) = ; my @res = unpack $big? "v3A*" : "n3A*", ...; ...; } sub record_bar { my( $big, ... ) = ; my @res = unpack $big? "v2A*" : "n2A*", ...; ...; }