in reply to Behaviour of unpack() with the Z template
I think perl is simply trying to be "symmetric" in packing/unpacking. When packing, "Z" adds NUL to original data. Out of symmetry, when unpacking "Z" should remove that added NUL. The documentation is not clear about this aspect. So I would suggest to understand it as
Maybe some day, someone will actually update the docs :) Or change the behavior of "Z*" to get data to first NUL only, which would allow stuff likeWhen unpacking, A strips trailing whitespace and nulls, Z strips everything from the first null to the end, and a returns data with no stripping at all.
Though changing of docs is more likely :)$b = pack("Z*C", "test", 10) ($str, $byte) = unpack("Z*C", $b);
EDIT. I'm wrong. In fact the "Z*" already takes the data to the first NUL and does not grab the rest. So, the above example actually works. But the documentation is completely incorrect. It should read
and a returns everything with no stripping at all.When unpacking, a grabs everything and returns unchanged, A grabs everything but strips from first null to the end and trailing spaces. Z stops after first null, the null is stripped from data.
In Section
Seekers of Perl Wisdom