Perl perlpacktut doesn't make sense to me

I am REALLY confused about package definition and unpacking for perl. Below is an excerpt from perl.doc.org

The pack function converts the values ​​into a sequence of bytes containing representations in accordance with this specification, the so-called argument "pattern". unpack is the reverse process, getting some values ​​from the contents of a byte string.

So, I understand that a package takes things human-readable (like A) and turns it into a binary format. Am I mistaken in this interpretation?

So, this is my interpretation, but then the same document immediately proceeds to give this example, which put my understanding in the opposite direction.

my( $hex ) = unpack( 'H*', $mem );
print "$hex\n";

What am I missing?

+4
source share
1

pack . () , - . (, ). , . .

, , 65 000 , .

print pack  A6', 137, $ARGV[0];

, , :

$ perl pack.pl Snoopy | hexdump -C
00000000  89 00 53 6e 6f 6f 70 79                           |..Snoopy|

, . S (, "", , ). 137, 0x8900. "Snoopy" .

:

$ perl test.pl Linus | hexdump -C
00000000  89 00 4c 69 6e 75 73 20                           |..Linus |

(0x20). - . :

$ perl test.pl 'Peppermint Patty' | hexdump -C
00000000  89 00 50 65 70 70 65 72                           |..Pepper|

, .

, - - . , . , , . , $tidy_little_package. , :

my( $id, $name ) = unpack  A6', $tidy_little_package;

. , . , .

pack Perl Perl.

+7

Source: https://habr.com/ru/post/1689170/


All Articles