Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Align string on a 32-bit boundary with padding

by hippo (Bishop)
on Aug 18, 2022 at 10:16 UTC ( [id://11146220]=note: print w/replies, xml ) Need Help??


in reply to Align string on a 32-bit boundary with padding

There are so many ways to do this. Here's one:

use strict; use warnings; use Test::More tests => 1; my $have = '6578616d706c652e6d65'; my $want = '6578616d706c652e6d650000'; my $mult = 8; my $padchar = '0'; my $padlen = length ($have) % $mult; $have .= $padchar x ($mult - $padlen) if $padlen; is $have, $want;

See also the FAQ.

without use any external module?

You mean like String::Pad for instance? Why not use the best and most extensive archive of modules on the net?


🦛

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-24 05:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found