in reply to Re: Mysteries of unpack("a", ...)
in thread Mysteries of unpack("a", ...)

Or rather

substr substr(do { _utf8_off(my $internal = $_); $internal }, 0, 4) . chr(0) x 4, 0, 4;

How's that! (for out-pedanting the pedant! (Always assuming I got it right :)

From perlfunc:pack (I'm too tired to fix up the link):

a A string with arbitrary binary data, will be null padded.

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^3: Mysteries of unpack("a", ...)
by ikegami (Patriarch) on Jan 03, 2009 at 06:58 UTC

    That's wrong.

    While pack (whose documentation you quoted) will add NULs, unpack doesn't.

    >perl -le"print length unpack 'a4', ''" 0

    If anything, unpack should do the opposite (remove trailing NULs), but it doesn't do that either.

    >perl -le"print length unpack 'a4', qq{\0\0\0\0}" 4