Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: Splitting a string to chunks

by johngg (Canon)
on Nov 29, 2006 at 23:25 UTC ( #586840=note: print w/replies, xml ) Need Help??


in reply to Re^2: Splitting a string to chunks
in thread Splitting a string to chunks

I think your "padding" algorith might be a bit wonky. Given a string of length, say, 19 characters you would arrive at a $padding value of 3, thus padding your $str with three "x"s to end up with a length of 22, not 24 as I think you wanted. This should work (not tested)

my $padding = 8 - ($str % 8);

The remove padding part would be something like (again, not tested)

substr $arr[-1], -$padding, $padding, q{} if $padding;

Cheers,

JohnGG

Update: I must have been half-asleep; where's the length call? Line should be

my $padding = 8 - (length($str) % 8);

You can't do modulo on a string :)

$ perl -le '$str = q{abc}; $pad = $str % 8; print $pad;' 0 $ perl -le '$str = q{abcdefghijkl}; $pad = $str % 8; print $pad;' 0 $

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2021-09-23 20:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?