in reply to Any caveats in using unpack to right-trim? Why isn't it advertised more?

I have mixed feelings about this. On one hand, I find it fascinating that unpack does this and does it so much faster. On the other hand, unless my application is processing huge volumes of text, for the sake of clarity I would opt for the "usual" way.

If I were in a situation where this feature of unpack provided a noticeable performance boost (based on the application and the data being processed) I would add a generous dose of comments explaining what was being accomplished using unpack this way, and why, for the sake (and sanity) of future maintainers. :)

"It's not how hard you work, it's how much you get done."

  • Comment on Re: Any caveats in using unpack to right-trim? Why isn't it advertised more?

Replies are listed 'Best First'.
Re^2: Any caveats in using unpack to right-trim? Why isn't it advertised more?
by syphilis (Archbishop) on Feb 09, 2025 at 08:29 UTC
    I have mixed feelings about this.

    I'm a bit puzzled by it.
    The "A*" format apparently removes trailing whitespace, but not embedded whitespace:
    D:\>perl -wle "print '#' . unpack('A*', 'abc ') . '#';" #abc# D:\>perl -wle "print '#' . unpack('A*', 'abc d') . '#';" #abc d#
    How is all of that explained as being "expected behaviour" ?
    Duh - it's explicitly stated in the documentation - " When unpacking, "A" strips trailing whitespace and nulls".

    Cheers,
    Rob