Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

by roho (Bishop)
on Feb 09, 2025 at 06:25 UTC ( [id://11163958]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11163958]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2025-11-10 07:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (66 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.