[HN Gopher] Demystifying pack and unpack, these most misundersto...
___________________________________________________________________
Demystifying pack and unpack, these most misunderstood functions
Author : psychoslave
Score : 67 points
Date : 2022-06-28 13:14 UTC (9 hours ago)
(HTM) web link (perldoc.perl.org)
(TXT) w3m dump (perldoc.perl.org)
| emmelaich wrote:
| This documentation is a model of clarity.
| layer8 wrote:
| A lot of Perl documentation is.
| KaiserPro wrote:
| It is just wonderfully readable
| andrewshadura wrote:
| What exactly is mysterious and misunderstood about pack and
| unpack? I personally understood it right from the start.
| lupire wrote:
| It's conceptually simple, but like changing bases in math, the
| notation is confusing and the different numeric/string
| datatypes are not clearly annotated.
| Isamu wrote:
| I used it very extensively and still found myself confused
| sometimes with complicated situations where I would have to
| unpack and then pack the results, or vice versa.
|
| It's powerful and terse, you can use it in so many situations
| to accomplish so much.
| znpy wrote:
| many years ago while playing with CGI (CGI::Simple? can't
| remember now) i saw a line that parsed the query string by means
| of unpack... It was short and terse, it felt like black magic.
| jefftk wrote:
| Python equivalent: https://docs.python.org/3/library/struct.html
| richard_todd wrote:
| Pack is great, but one feature I always wish for is to pack into
| the middle of an existing string. So instead I have to pack into
| a new string and then copy it into the destination. Python has
| struct.pack_into for this case. I know the performance difference
| would be small, and if I really care so much about efficiency I
| shouldn't write it in a scripting language anyway. It's just one
| of those things that bugs me.
| mfontani wrote:
| $ perl -E'$s = "bar"; substr($s, 1, 1) = pack("A*", 60); say
| $s' b60r
| jandrese wrote:
| I really appreciate this. pack and unpack are the two functions
| that give me the most trouble in perl by far. They look so simple
| but the implementation details are killer.
___________________________________________________________________
(page generated 2022-06-28 23:01 UTC)