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


In reply to Re: print packed string by johngg
in thread print packed string by lightoverhead

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.