Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: pack auto-chomps/chops?

by ikegami (Patriarch)
on Oct 07, 2009 at 18:49 UTC ( [id://799779]=note: print w/replies, xml ) Need Help??


in reply to pack auto-chomps/chops?

pack:

A: A text (ASCII) string, will be space padded

Emphasis mine. If spaces are added by pack, they'll be removed by unpack. I guess it means \s when it says space. Fix:

sub by_ip { return map substr($_, 4), sort map inet_aton( (split /\s/, $_, 2)[0] ) . $_, @_ }

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

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

      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.

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://799779]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-26 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found