Do you know where your variables are? | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Hi Monks. I'm currently improving my Perl by practising Perl idioms and trying to write more 'Perlish' code. I'm currently practising by parsing a binary blob with unpack. My input is a scalar, and my desired output is an array of arrays. As I'm from a C background my initial approach is to use the C-like for loop and I end up with code like the following:
While it works, it seems unnecessarily verbose for Perl and I'm aware I'm trying to write C in Perl. Therefore, I've been attempting to rewrite the code in a more Perlish manner. I've ended up with the following:
I'm happy with the map { unpack ... } ... construct as this is clear and concise, but I'm a little less sure about the first unpack to split the $data scalar into the list of items. Therefore I'm deferring to the wisdom of the Monks, is there a better way to achieve what I am doing? Maybe the approach should be a single unpack "(CA4)*", $data and then rebuilding the child lists? In reply to Perlish approach to parsing a binary blob by mxb
|
|