in reply to Re^2: Splitting a string to chunks
in thread Splitting a string to chunks
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 $
|
---|