If "L" in "blob" stands for "large", and script is anything but a throw-away one-liner, I'd be unhappy about implicitly building large useless intermediate lists.

use strict; use warnings; use feature 'say'; use Data::Dump 'dd'; use Benchmark 'cmpthese'; my $data = "1ABCD2EFGH3IJKL4MNOP5QRST6UVWX" x 1000; cmpthese -3, { 1 => sub { my @out; for ( my $x = 0; $x < length $data; $x += 5 ) { push @out, [ unpack "CA4", substr $data, $x, 5 ] } return \@out }, 2 => sub { [ map [ unpack 'CA4', $_ ], unpack "(A5)*", $data ] } }; __END__ Rate 2 1 2 34.2/s -- -21% 1 43.1/s 26% --

In reply to Re: Perlish approach to parsing a binary blob by vr
in thread Perlish approach to parsing a binary blob by mxb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.