What do you mean, exactly, by the "first answer"? Both
vroom's and my answer's define a pad subroutine that
you can give a string and a length that you want the
padded string to be. They accomplish the end result in
different ways, but both work, and neither assume that
you must know the string length beforehand.