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
$
|