This pack, unpack in "Perl language programming" has introduced
It looks complicated.
1 # Convert a string to hex format
2 my $source = ‘abcd‘;
3 unpack(‘H*‘, $source);
4 # Description, this ‘H’ is a description of conversion to hexadecimal, the following * is any length, that is, how much is it after conversion?
5 #If you simply write unpack(‘H‘, $source), only the first character of the converted hexadecimal character is displayed.
6
7 # For example, if you want to convert a hexadecimal to ASCII, you can do this:
8 # hexadecimal string
9 $hex = "61626364";
10
11 #转ASCII
12 $bin = pack(‘H*‘, $hex);
13 print "$bin\n";
14
15
16 # This pack and unpack can extract data in addition to the hexadecimal, for example, have the following string:
17 my $data = ‘1234567890aABCDE,FG’;
18 #We want to raise 1234567890 and ABCDE FG, you can do this:
19 my($one, $two, $three) = unpack(‘A10xA5xa2‘, $data)
20 # A character here, it is represented by an A.
21 How many characters are there, just add a number after A, such as ‘ABC’, which is three characters, which means: A3
22 #如1234567890 has ten characters, it means A10
23 and the lowercase a, we don't want, it is represented by x, this x means skip, and it represents null in pack.
24 # Of course, if you want to extract all the bytes, you can add * after it, such as A*
Transferred from: https://blog.gtwang.org/perl/perl-pack-unpack-tutorial/
Pack and unpack in Perl