Perl: the Markov chain saw PerlMonks

### Re^2: pack auto-chomps/chops?

by bv (Friar)
 on Oct 07, 2009 at 19:14 UTC ( #799788=note: print w/replies, xml ) Need Help??

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

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?

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

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

Replies are listed 'Best First'.
Re^3: pack auto-chomps/chops?
by ikegami (Patriarch) on Oct 07, 2009 at 19:18 UTC

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

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)))

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://799788]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2023-12-02 05:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
What's your preferred 'use VERSION' for new CPAN modules in 2023?

Results (13 votes). Check out past polls.

Notices?