Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Perlish approach to parsing a binary blob

by AnomalousMonk (Bishop)
on Apr 09, 2018 at 14:17 UTC ( #1212592=note: print w/replies, xml ) Need Help??

in reply to Perlish approach to parsing a binary blob

... I'm a little less sure about the first unpack to split the $data scalar into the list of items.

Can you say more about why you are unsure about this statement? Is it because of the interpolated  $entry_size component in the unpack template? If so, be assured that this is a perfectly kosher maneuver: a template specification string is just a string no matter how compounded. (Sometimes a string is just a string...)

Update 1: Changed a word, added a link.

Update 2: Hey, this is very late, but I just noticed that the unpack documentation includes an example of this exact technique in a limited implementation of substr:

sub substr { my($what,$where,$howmuch) = @_; unpack("x$where a$howmuch", $what); }

Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^2: Perlish approach to parsing a binary blob
by mxb (Pilgrim) on Apr 09, 2018 at 14:35 UTC


    Yes, I think that's pretty much hit it straight on.

    The "(a$entry_size)*" just looked a bit odd when I first wrote it. I'm glad to see that is a reasonably common approach and does not immediately scream out as "bad code" or "obfuscation"


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (1)
As of 2021-09-20 17:31 GMT
Find Nodes?
    Voting Booth?

    No recent polls found