Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Perlish approach to parsing a binary blob

by choroba (Archbishop)
on Apr 09, 2018 at 12:48 UTC ( #1212584=note: print w/replies, xml ) Need Help??


in reply to Perlish approach to parsing a binary blob

If you don't mind having a structure that stores something else at the beginning, you can use one unpack and then change the structure in place. It seems almost 10% faster on my machine:
my $data = "1ABCD2EFGH3IJKL4MNOP5QRST6UVWX"; my $entry_size = 5; my $a_size = $entry_size - 1; my @out = unpack "(CA$a_size)*", $data; push @out, [ splice @out, 0, 2 ] for 1 .. @out / 2;

Update: BrowserUk's solution seems even faster, adding again almost 10%.

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1212584]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2020-09-30 01:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (156 votes). Check out past polls.

    Notices?