in reply to sprintf to zero-pad on the right

How about avoiding sprintf altogether?
my $string = 'TEST'; $string .= '0000';
Update: If you have a variable length string, then use
$string .= '0' x ($fixed_length - length $string);
to pad it to the desired $fixed_length.

-Mark

Replies are listed 'Best First'.
Re: Re: sprintf question
by Anonymous Monk on Mar 15, 2004 at 16:33 UTC

    Hi Mark, thanks for your reply and I should have explained further.

    The total length I'm looking for is 8. So if I see a four character string (i.e TEST) I know I should append 4 zeros. If I see a three character string, I would append 5 zeros etc.

    I thought sprintf would be a natural choice for this but couldn't get it to work...