in reply to Remove whitespace in string and maintain overall length
kennethk's solution works, but can be made more efficient:
my $address = "$strnum $strname $strtype $strdir"; $address =~ s/\s+/ /g; $address .= ' ' x (37 - (length $address));
The expression, ' ' x $n gives you a string of $n spaces with much less overhead than a while or for loop.
Disclaimer: Not tested. There may be an off by 1 error in calculating the length of the padding.
|
|---|