in reply to Re^2: pack auto-chomps/chops?
in thread pack auto-chomps/chops?

your solution works but is slower than just appending a "\n" to the end during the final map

If pack is faster — seems odd — you could use Z instead of A.

Ah, that's tricky. I suppose you're right, though. Do you know if there's a web-browsable version of the Perl source code anywhere I could check into that?

http://perl5.git.perl.org/perl.git Look for pp_unpack in pp*.c (probably pp.c specifically pp_pack.c).

The relevant code:

1458 for (ptr = s+len-1; ptr >= s; ptr--) 1459 if (*ptr != 0 && !isSPACE(*ptr)) break; 1460 ptr++;

and

#define isSPACE(c) \ ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) =='\r' || (c) + == '\f')
aka \s

Update: Added relevant code.

Replies are listed 'Best First'.
Re^4: pack auto-chomps/chops?
by bv (Friar) on Oct 07, 2009 at 20:04 UTC

    Thanks, that really helps clear it up. As far as speed goes, I increased my data set and the 3 solutions (pack-and-append, pack-with-Z, and substr) are very tightly tied. I'll go with the Z approach for my final code.

    print pack("A25",pack("V*",map{1919242272+$_}(34481450,-49737472,6228,0,-285028276,6979,-1380265972)))