in reply to Re^2: Interleaving bytes in a string quickly
in thread Interleaving bytes in a string quickly


Then maybe something like this. It should still be ~25 faster than the original for the general case:
sub interleave { my $str = shift; my $filler = 64; # Char number. my $hi_bytes = pack 'v*', unpack 'C*', $str; my $lo_bytes = pack 'n*', ($filler) x length $str; return $hi_bytes | $lo_bytes; }

--
John.

Replies are listed 'Best First'.
Re^4: Interleaving bytes in a string quickly
by salva (Canon) on Feb 26, 2010 at 15:27 UTC
    this variation...
    $s = time; $out4 = (pack 'v*', unpack 'C*', $buf) | ("\x00$filler" x length $buf) +; print time() - $s, "\n";
    ... introduces very low overhead.