Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: print packed string

by johngg (Abbot)
on May 31, 2013 at 23:18 UTC ( #1036348=note: print w/ replies, xml ) Need Help??


in reply to print packed string

I find that pack is easier to understand with code examples that pipe the packed string into hexdump. The last snippet is just packing the ASCII character set.

$ perl -e 'print pack q{H*}, sprintf q{%2x}, 0x3a;' | hexdump -C 00000000 3a |:| 00000001
$ perl -e ' print pack q{(H*)*}, map { sprintf q{%2x}, $_ } 0b111010, 072, 58, 0x3a;' | hexdump -C 00000000 3a 3a 3a 3a |::::| 00000004
$ perl -e ' print pack q{(H*)*}, map { sprintf q{%2x}, $_ } 0 .. 127;' | hexdump -C 00000000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f |......... +.......| 00000010 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f |......... +.......| 00000020 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f | !"#$%&'( +)*+,-./| 00000030 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f |012345678 +9:;<=>?| 00000040 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f |@ABCDEFGH +IJKLMNO| 00000050 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f |PQRSTUVWX +YZ[\]^_| 00000060 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f |`abcdefgh +ijklmno| 00000070 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f |pqrstuvwx +yz{|}~.| 00000080

I hope that you also find these examples helpful.

Cheers,

JohnGG


Comment on Re: print packed string
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2014-09-17 23:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (100 votes), past polls