Skip to content

Commit 070b513

Browse files
committed
perlpacktut: Remove some jargon, flesh out
Fixes #22697
1 parent d85c3a2 commit 070b513

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

pod/perlpacktut.pod

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ of these two functions.
4141

4242
To see how (un)packing works, we'll start with a simple template
4343
code where the conversion is in low gear: between the contents of a byte
44-
sequence and a string of hexadecimal digits. Let's use C<unpack>, since
45-
this is likely to remind you of a dump program, or some desperate last
46-
message unfortunate programs are wont to throw at you before they expire
47-
into the wild blue yonder. Assuming that the variable C<$mem> holds a
48-
sequence of bytes that we'd like to inspect without assuming anything
44+
sequence and a string of hexadecimal digits. The example we've chosen
45+
looks like a crash dump, and shows how C<unpack> can be used to make
46+
sense of things like this. Assuming that the variable C<$mem> holds a
47+
sequence of bytes that we'd like to inspect without assuming anything
4948
about its meaning, we can write
5049

5150
my( $hex ) = unpack( 'H*', $mem );
@@ -58,17 +57,21 @@ corresponding to a byte:
5857

5958
What was in this chunk of memory? Numbers, characters, or a mixture of
6059
both? Assuming that we're on a computer where ASCII (or some similar)
61-
encoding is used: hexadecimal values in the range C<0x40> - C<0x5A>
60+
encoding is used: hexadecimal values in the range C<0x41> - C<0x5A>
6261
indicate an uppercase letter, and C<0x20> encodes a space. So we might
63-
assume it is a piece of text, which some are able to read like a tabloid;
64-
but others will have to get hold of an ASCII table and relive that
65-
firstgrader feeling. Not caring too much about which way to read this,
62+
assume it is a piece of ASCII text. We can verify that by doing
63+
64+
print unpack( 'A*', $mem), "\n"
65+
66+
A MAN A PLAN A CANAL PANAMA
67+
68+
Going back to the original C<H*> for the purposes of this tutorial,
6669
we note that C<unpack> with the template code C<H> converts the contents
6770
of a sequence of bytes into the customary hexadecimal notation. Since
6871
"a sequence of" is a pretty vague indication of quantity, C<H> has been
6972
defined to convert just a single hexadecimal digit unless it is followed
7073
by a repeat count. An asterisk for the repeat count means to use whatever
71-
remains.
74+
remains. That is also the case for the C<A*> above.
7275

7376
The inverse operation - packing byte contents from a string of hexadecimal
7477
digits - is just as easily written. For instance:

0 commit comments

Comments
 (0)