Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

perl pack/unpack compiled version

by pwagyi (Monk)
on Mar 27, 2018 at 08:24 UTC ( [id://1211828] : perlquestion . print w/replies, xml ) Need Help??

pwagyi has asked for the wisdom of the Perl Monks concerning the following question:

Greeting monks!

I am just wondering if there is any module on CPAN that is counterpart to built-in pack/unpack. That will offer compiled template (for fixed template), so that for performance critical bits, compiled pack/unpack could be used. I believe clojure/python has something similar.

#hypothetical module use Binary::Parser; $compiled_template = Binary::Parser->new( template => 'nCC C/a'); my @result = $compiled_template->unpack($binary_data); # would be nice to have, like regex ? (0 or one) at the end # it will match C C/a # C C/a B8 # C C/a B8 f ... $optional_template = Binary::Parser->new( template => 'C C/a (B8 ff c +c)?');

Replies are listed 'Best First'.
Re: perl pack/unpack compiled version
by Anonymous Monk on Mar 27, 2018 at 11:09 UTC
    Pack/unpack is fairly optimized. Usually faster than dropping into some xs stuff. See convert::binary::c