3 ms·
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
by richard_todd 4y ago
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 4y ago$ perl -E'$s = "bar"; substr($s, 1, 1) = pack("A*", 60); say $s' b60r
- richard_todd 4y agoYou have just demonstrated copying the result of the call to pack() into a string. That's what I already do, but what I want is a version that just writes over bytes in $s without creating the "60" string.